60. Register Overlay byte and bitfield

 Your task is to define a union that allows accessing an 8-bit register both as a raw byte and as individual bitfields.

  • The union should contain:
    • uint8_t raw
    • A struct with fields:
      • unsigned en:1;
      • unsigned mode:3;
      • unsigned reserved:4;
         
  • The program will assign a value to the union and then print the en and mode fields.

     

Example
 Input:

13

Output:

en=1 mode=6

 

Explanation:

  • 13 = 0b00001101
  • en = bit0 = 1

mode = bits[1..3] = 110b = 6
 

Loading...

Input

13

Expected Output

en=1 mode=6