63. Register Bitfields Using Struct Overlay

You are implementing a simulated 8-bit control register where each bit controls a feature. Rather than using masks, you’ll use a bitfield struct to access individual bits.

The register layout is as follows:

BitFieldSize
0enable1
1–2mode2
3interrupt1
4–7reserved4

Your task is to:

  • Define a union that overlays:
    • A struct with bitfields: enable, mode, interrupt
    • A raw uint8_t register
  • Read values for enable, mode, interrupt from input
  • Construct the struct, and print the final register as an 8-bit unsigned value

Assume:

  • enable is 0 or 1
  • mode ranges from 0–3
  • interrupt is 0 or 1
     

Example-1

Input: 1 2 1
Output: 13

Explanation:

  • Binary = 00001101 → enable=1, mode=10, interrupt=1
     

Example-2

Input: 0 0 1
Output: 8

Binary = 00001000


 

Loading...

Input

1 2 1

Expected Output

13