#include <iostream>
#include <cstdint>
using namespace std;
class Reg32 {
private:
uint32_t value;
public:
// Initialize register with a 32-bit value
Reg32(uint32_t v) : value(v) {}
// Bitwise OR assignment
Reg32& operator|=(uint32_t x) {
value |= x;
return *this;
}
// Bitwise AND assignment
Reg32& operator&=(uint32_t x) {
value &= x;
return *this;
}
// Conversion operator for output
operator uint32_t() const {
return value;
}
};
int main() {
uint32_t init, orVal, andVal;
cin >> init >> orVal >> andVal;
Reg32 reg(init);
reg |= orVal;
reg &= andVal;
cout << (uint32_t)reg;
return 0;
}
Explanation & Logic Summary:
operator|= modifies the register by setting bits present in the input mask.operator&= masks the register, clearing bits not present in the input mask.uint32_t when printed or assigned.Firmware Relevance & Real-World Context:
This problem reflects real-world embedded scenarios such as:
It reinforces operator overloading, bitwise logic, and type safety, which are essential skills for Embedded C++ and firmware developers.
Input
8 5 14
Expected Output
12