Register Bitwise Operations

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

// Implement class Reg32 here

class Reg32{
    private:
    uint32_t value;

    public:
    explicit Reg32(int v) noexcept : value(v) {};
    Reg32 operator|=(uint32_t other)
    {
        this->value |= other;
        return *this;
    }

    Reg32 operator&=(uint32_t other)
    {
        this->value &= other;
        return *this;
    }

    operator uint32_t() const
    {
        return this->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

 

 

 

 

 

Upvote
Downvote
Loading...

Input

8 5 14

Expected Output

12