73. Unions-I

Question.7

Two developers extract the second byte (bits 8–15) from a uint32_t value:

Developer A — Union:

union { uint32_t val; uint8_t b[4]; } u;
u.val = data;
byte1 = u.b[1];

Developer B — Shift and mask:

byte1 = (data >> 8) & 0xFF;

Which approach is more portable across architectures?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!