#include <iostream>
#include <cstdint>
using namespace std;
/**
* Reg32 Class
* Simulates a 32-bit hardware register with bitwise manipulation capabilities.
*/
class Reg32 {
private:
uint32_t value; // Internal storage for the 32-bit register value
public:
// Constructor to initialize the register
Reg32(uint32_t initial_value) : value(initial_value) {}
// Overload bitwise OR assignment operator
// This performs: value = value | rhs
Reg32& operator|=(uint32_t rhs) {
this->value |= rhs;
return *this;
}
// Overload bitwise AND assignment operator
// This performs: value = value & rhs
Reg32& operator&=(uint32_t rhs) {
this->value &= rhs;
return *this;
}
// Conversion operator to allow the object to be used as a uint32_t
// The 'const' ensures we don't modify the register during a read/print
operator uint32_t() const {
return value;
}
};
int main() {
uint32_t init, orVal, andVal;
// Read input values: initial, value to OR, value to AND
if (!(cin >> init >> orVal >> andVal)) return 0;
// Initialize the register object
Reg32 reg(init);
// Apply the bitwise operations using our overloaded operators
reg |= orVal; // bitwise OR
reg &= andVal; // bitwise AND
// Print the final result by casting the object to uint32_t
cout << (uint32_t)reg << endl;
return 0;
}
Input
8 5 14
Expected Output
12