123. Register Operator Overloading

You are implementing firmware that manipulates a 32-bit memory-mapped control register.

To improve readability and safety, all register bit manipulation must be expressed using operator overloading, not raw bitwise expressions scattered throughout the firmware logic.

You are given a partially implemented program.
The program flow and logic are fixed.

Your task is to modify only the Register32 class so that the program:

  • Compiles successfully
  • Applies all register operations correctly
  • Produces the expected output for all test cases

Input / Program Flow:

The program receives:

  • An integer N — number of operations
  • N lines, each describing an operation:
    • SET x → set bit x
    • CLEAR x → clear bit x

The initial register value is always 0.

 

Required Behavior:

  • Apply all operations in order
  • Print the final register value as an unsigned integer

Output Format:

Print exactly:

reg=<final_value>

 

Example

Input:

3
SET 0
SET 3
CLEAR 0 

Explanation:

  • Initial register value = 0
  • SET 0 → register becomes 0000 0001 (decimal 1)
  • SET 3 → register becomes 0000 1001 (decimal 9)
  • CLEAR 0 → register becomes 0000 1000 (decimal 8)

Output:

reg=8

 

Constraints:

  • The register is exactly 32 bits wide
  • Bit index x is guaranteed to be in the range 0–31
  • All input is guaranteed valid — no runtime validation is required
  • You must not modify main()
  • You must not modify control flow
  • The following lines must remain unchanged:

    reg |= (1u << bit); 
    reg &= ~(1u << bit);
  • You may only modify the Register32 class
  • No runtime conditionals inside the register abstraction
  • No virtual functions
  • No inheritance
  • No heap allocation
  • No STL containers
  • Operator behavior must be resolved entirely at compile time

 

 

 

Loading...

Input

3 SET 0 SET 3 CLEAR 0

Expected Output

reg=8