148. ADC Sample Union View

Your task is to define a struct named AdcSample that represents a 16-bit ADC sample with a timestamp.

The structure must contain:

  • A uint32_t field named timestamp
  • An anonymous union containing:
    • A uint16_t value named raw
    • A struct containing:
      • uint8_t lo (least significant byte)
      • uint8_t hi (most significant byte)

The program will:

  1. Read a timestamp (decimal)
  2. Read a raw ADC value (hexadecimal, prefixed with 0x)
  3. Assign values to the struct
  4. Print the timestamp, low byte, and high byte in hexadecimal format

Example

Input:

1000 0x03F2 

Output:

ts=1000 lo=0xF2 hi=0x03

Explanation:

  • raw = 0x03F2
  • lo = 0xF2
  • hi = 0x03

⚠️ Assumptions (MANDATORY)

  • The target system is little-endian
  • The code is intended for embedded / firmware environments where union-based register overlays are commonly used
  • Accessing different union members is allowed as a representation view

 

 

 

Loading...

Input

1000 0x0000

Expected Output

ts=1000 lo=0x00 hi=0x00