Skip to content
๐Ÿง  Endianness

๐Ÿง  Endianness

๐Ÿ“˜ Overview

Endianness defines how multi-byte data (e.g. 16-bit, 32-bit, 64-bit) is stored in memory. It determines the byte orderโ€”not digit orderโ€”used to represent values.

TermDefinition
Big-endianStores the Most Significant Value (MSV) first
Little-endianStores the Least Significant Value (LSV) first

๐Ÿ“š Etymology & Semantic Ancestry

The term “endian” originates from Jonathan Swiftโ€™s Gulliverโ€™s Travels (1726), where two factionsโ€”the Big-Endians and Little-Endiansโ€”argue over which end of a boiled egg to crack first. Swift used this absurd conflict to satirize religious and political disputes.

Thus the word is End-ian

In 1980, computer scientist Danny Cohen repurposed the metaphor in an Internet Experiment Note to describe byte-order disagreements between computer architectures. He coined:

  • Big-endian: MSB-first systems
  • Little-endian: LSB-first systems

๐Ÿ” Byte Layout Comparison

Example: 0x12345678 (32-bit integer)

FormatByte Sequence (Low โ†’ High Address)
Big-endian12 34 56 78
Little-endian78 56 34 12

Visual Anchor

Memory Address โ†’   0x00   0x01   0x02   0x03
Big-endian     โ†’   0x12   0x34   0x56   0x78
Little-endian  โ†’   0x78   0x56   0x34   0x12

๐Ÿงฉ Semantic Flags

FlagBig-endianLittle-endian
<code>#human-readable</code>โœ… Matches decimal notationโŒ Counterintuitive to humans
<code>#network-standard</code>โœ… Used in TCP/IP, DNS, etc.โŒ Requires conversion
<code>#arithmetic-efficiency</code>โŒ Harder to start with LSBโœ… Easier for incremental ops
<code>#sign-bit-access</code>โœ… MSB at lowest addressโŒ MSB at highest address
<code>#binary-comparison</code>โœ… Lexicographically alignedโŒ Needs reordering for MSB-first
<code>#memory-fetch</code>โŒ No major advantageโœ… Historically faster on byte-wise CPUs

โœ… Big-endian Preferred

  • Network protocols: TCP/IP, DNS, HTTP headers (<code>#network-standard</code>)
  • Binary formats: JPEG, MPEG, EXIF (<code>#human-readable</code>)
  • Embedded systems: Hex dumps for diagnostics (<code>#sign-bit-access</code>)

โŒ Big-endian Avoided

  • x86/x64 systems: Native little-endian architecture
  • Low-level arithmetic: Harder to start from LSB (<code>#arithmetic-efficiency</code>)

โœ… Little-endian Preferred

  • Intel/AMD CPUs: Native format (<code>#memory-fetch</code>)
  • Arithmetic-heavy systems: Easier overflow detection, addition (<code>#arithmetic-efficiency</code>)
  • Low-level debugging: Easier to trace LSB-first logic

โŒ Little-endian Avoided

  • Cross-platform communication: Requires conversion to big-endian
  • Lexicographic sorting: MSB-last complicates binary comparison

๐Ÿง  Motivation Analogy

Think of endianness like stacking books:

  • Big-endian: Title page on top โ†’ easy to identify the book
  • Little-endian: Index page on top โ†’ efficient if you’re flipping from the back
Last updated on