158. Byte Splitter Union

Your task is to define a union that allows viewing a 16-bit unsigned value both as a full word and as two separate bytes on a little-endian system.

The union must contain:

  • uint16_t word
  • uint8_t bytes[2]

Assume the target system uses little-endian byte order, where:

  • bytes[0] contains the least significant byte (LSB)
  • bytes[1] contains the most significant byte (MSB)

The program will:

  1. Read a 16-bit unsigned integer from input
  2. Assign it to the union
  3. Print the LSB and MSB values as decimal numbers

Example:

Input

4660 

Output

LSB=52 MSB=18 

Explanation

4660 = 0x1234

  • LSB = 0x34 = 52
  • MSB = 0x12 = 18

Constraints

  • Input range: 0 to 65535
  • Target architecture: little-endian
  • No overflow handling is required beyond uint16_t

 

 

 

Loading...

Input

4660

Expected Output

LSB=52 MSB=18