74. Unions-II

Question.6

MCU-A (little-endian ARM) transmits a float using a union:

union { float f; uint8_t b[4]; } tx;
tx.f = 1.0f;  // IEEE 754: 0x3F800000
// Sends: b[0]=0x00, b[1]=0x00, b[2]=0x80, b[3]=0x3F

MCU-B (big-endian PowerPC) receives the same 4 bytes and reassembles:

union { float f; uint8_t b[4]; } rx;
rx.b[0]=0x00; rx.b[1]=0x00; rx.b[2]=0x80; rx.b[3]=0x3F;
printf("%.1f", rx.f);

Will MCU-B correctly reconstruct 1.0f?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!