12. Register Representation 8-bit

 Frame a class Register8 with the following:

  • Private data member:
    • value (8-bit register value, start at 0)
  • Public methods:
    • void setBit(int pos) → set bit at position pos (0–7)
    • void clearBit(int pos) → clear bit at position pos (0–7)
    • void toggleBit(int pos) → toggle bit at position pos (0–7)
    • unsigned char getValue() const → return current 8-bit value
       

The input will contain:

  •   n (number of operations)
  • followed by n operations, each line is one of: set pos, clear pos, toggle pos
     

Example
 Input:

3
set 0
set 2
toggle 2

Output:

1

Here, n = 3. Operations: set bit 0 → 00000001 (1), set bit 2 → 00000101 (5), toggle bit 2 → 00000001 (1).

 

Input:

4
set 7
set 0
clear 7
toggle 1

Output:

3

Explanation: After operations, the register is 00000011 (decimal 3).

Loading...

Input

3 set 0 set 2 toggle 2

Expected Output

1