In embedded and firmware systems, hardware registers are often manipulated using bitwise operations such as OR and AND to set, clear, or mask specific bits.
Your task is to implement a C++ class named Reg32 that represents a 32-bit hardware register and supports controlled bitwise operations using operator overloading.
The register must store an unsigned 32-bit value and allow modification using bitwise OR and AND assignments, similar to how registers are manipulated in low-level firmware code.
Task Requirements
Implement a class Reg32 that:
uint32_t value internally.reg |= x; → Performs a bitwise OR between the register value and xreg &= x; → Performs a bitwise AND between the register value and xoperator uint32_t() const;Program Flow
initial_value or_value and_value
Reg32 object initialized with initial_value.reg |= or_value;
reg &= and_value;
Input Format
Three space-separated unsigned integers:
initial_value or_value and_value
Output Format
A single unsigned integer representing the final register value after both operations.
Example
Input:
8 5 14
Binary Steps:
8 = 1000₂
5 = 0101₂ → OR → 1101₂ (13)
14 = 1110₂ → AND → 1100₂ (12)
Output:
12
Constraints
|= and &=operator uint32_t() must be implementeduint32_t for all register-related values
Input
8 5 14
Expected Output
12