Register Bitwise Operations

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

// Implement class Reg32 here
class Reg32 {
private:
    uint32_t regval;
public:
    Reg32(uint32_t i) : regval(i) {}
    
    void operator|=(uint32_t val) {
        regval |= val;
    }
    
    void operator&=(uint32_t val) {
        regval &= val;
    }
    
    operator uint32_t() const {
        return regval;
    }  
};

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