Create a class Reg8 that simulates an 8-bit hardware register.
Class Requirements:
The class must:
uint8_t register valueReg8() → initializes the register to 0void write(uint8_t v) → writes a new value to the registeruint8_t read() → returns the current register valuevoid setBit(int bit) → sets the specified bit only if bit is in range 0–7void clearBit(int bit) → clears the specified bit only if bit is in range 0–7⚠️ If bit is outside the range 0–7, the register must remain unchanged.
In main():
initialValuebitToSetbitToClearinitialValue to the registerbitToSetbitToClearExample Input:
10
1
3
Example Output:
2
Explanation:
initialValue = 10 = 00001010₂1 → already set → unchanged3 → 00000010₂2Constraints:
Input
10 1 3
Expected Output
2