Register Bitwise Operations

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

// Implement class Reg32 here

class Reg32 {
    private:
      uint32_t value;
    public:
      Reg32 (uint32_t x): value(x){}
      Reg32 operator |= (const uint32_t x){
        value |= x;
        return value; 
      }
      Reg32 operator &= (const uint32_t x){
        value &= x;
        return value; 
      }
        operator uint32_t() const {
        return value;
      }
      
 };

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

 

 

operator uint32_t() const{

        return value;

      }

 

 

Upvote
Downvote
Loading...

Input

8 5 14

Expected Output

12