System Design: Endianness

Q: Why on earth we have endianness?

A: It’s a matter of hardware. Computer memory is just a sequence of cells which are just bytes. A 32-bit processor has 32-bit registers that store 32/8=4 bytes. Endianness happens when data is loaded/stored between registers and memory. Big-endian stores the high-byte(significant byte) in registers as the low byte in memory. Little-endian does the opposite.

Q: Why couldn’t the world agree on one universal standard of endianness?

Each endian has its own strengths in specfic application domains. Internet protocols/Telephone network are standardized with Big-endian. Just like IP addresses, the high-order byte/number is sent first as the area code. Little-endian simplifies arithmetic calculation for assembly programming because we humans start at the lower digit when we do add/minus/divide. Also, with little-endian, reading a 64-bit number is the same as reading 32-bit number(still the calculation order).

Leave a comment