๐ง 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.
| Term | Definition |
|---|---|
| Big-endian | Stores the Most Significant Value (MSV) first |
| Little-endian | Stores 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)
| Format | Byte Sequence (Low โ High Address) |
|---|---|
| Big-endian | 12 34 56 78 |
| Little-endian | 78 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
| Flag | Big-endian | Little-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