-
Notifications
You must be signed in to change notification settings - Fork 0
Endianness
MarekBykowski edited this page May 26, 2026
·
1 revision
uint32_t x = 0x12345678
LITTLE ENDIAN (ARM / x86) BIG ENDIAN (network / TCP)
addr byte addr byte
+0 0x78 ← *p (LSB) +0 0x12 ← *p (MSB)
+1 0x56 +1 0x34
+2 0x34 +2 0x56
+3 0x12 (MSB) +3 0x78 (LSB)
// Endianness test
uint32_t x = 0x12345678;
uint8_t *p = (uint8_t *)&x;
if (*p == 0x78) puts("little endian");
else puts("big endian");
htonl(val); // host → network (big endian)
ntohl(val); // network → host