Register Bitwise Operations

#include <iostream>
#include <cstdint>
using namespace std;

// Implement class Reg32 here
class Reg32{
    uint32_t reg;
    public:
    Reg32(uint32_t v) : reg(v){}
    void operator|=(const uint32_t v){
        reg|=v;
    }
    void operator&=(const uint32_t v){
        reg&=v;
    }
    operator uint32_t()const{
        return reg;
    }
};
int main() {
    uint32_t init, orVal, andVal;
    cin >> init >> orVal >> andVal;

    Reg32 reg(init);

    reg |= orVal;     // bitwise OR
    reg &= andVal;    // bitwise AND

    cout << (uint32_t)reg;

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

8 5 14

Expected Output

12