5.1.11 · D2Instruction Set Architecture (ISA)

Visual walkthrough — Endianness (big vs little)

1,829 words8 min readBack to topic

This page rebuilds the parent note Endianness (big vs little) from absolute zero. Everything used is defined before it appears.


Step 1 — What is a byte, and what is an address?

WHAT. Memory is a long row of tiny boxes. Each box holds exactly one byte — a number from to . Each box has a numbered label called its address: Because every box has its own address, we call memory byte-addressable.

WHY. Before we can talk about the order of bytes, we must agree on what a byte is (one box, holding ) and what an address is (the box's numeric label). Order only means anything once boxes are lined up and numbered.

PICTURE. Look at the row of white boxes. The number under each box (grey) is its address; that address only counts boxes, not bits.

Figure — Endianness (big vs little)

Why ? A byte is bits, and distinct patterns, i.e. the values through . This links to Data Representation.


Step 2 — Why one box is not enough

WHAT. Take the 32-bit value Here "32-bit" means it needs bits bytes. One box holds only bits, so cannot fit in a single box.

WHY. This is the entire reason endianness exists: the value spans boxes, and boxes sit at consecutive addresses, so something must decide which quarter of goes in which box.

PICTURE. The full 32-bit bar is sliced into four 8-bit chunks. Each chunk is a byte we must place somewhere.

Figure — Endianness (big vs little)
  • — the leftmost two hex digits; the highest-weight chunk.
  • — the rightmost two hex digits; the lowest-weight chunk.

Step 3 — Significance: why the chunks are not equal

WHAT. The four chunks do not count the same. Reading as a real number:

Term by term:

  • — the top byte, multiplied by (shifted left bits). Biggest contribution → most significant byte (MSB).
  • — next byte, weight .
  • — weight .
  • — the "ones" byte, weight least significant byte (LSB).

WHY. We need this weighting before choosing a storage order, because the two conventions are literally defined by which weight lands at the lowest address. Without knowing which byte is "biggest," the words big-endian and little-endian have no meaning.

PICTURE. A bar chart of the four weights on a log scale — you can see that dominates and is tiny.

Figure — Endianness (big vs little)

Step 4 — Big-endian: put the big end first

WHAT. Store starting at base address . Big-endian rule: the MSB goes at the lowest address.

WHY. "Big-endian" = "big end first." Since the box at is the first box, we drop the biggest byte there. This makes a memory dump read left-to-right exactly like the human-written number .

PICTURE. Watch the four coloured chunks fall straight down into the boxes in the same order they appear in the number — no crossing wires.

Figure — Endianness (big vs little)

In formula form, at offset :

  • — the reversed index. At we want the top byte ; at we want . So . ✓

Step 5 — Little-endian: put the little end first

WHAT. Same value, same base . Little-endian rule: the LSB goes at the lowest address.

WHY. "Little end first." The ones-byte sits at the smallest address. Notice the elegant match: the byte at offset is exactly — offset equals significance index.

PICTURE. Now the chunks cross over: the rightmost chunk swings to the leftmost box. The crossing wires are the visual signature of little-endian.

Figure — Endianness (big vs little)

  • — no reversal. , . ✓

Step 6 — The payoff case: reading fewer bytes

WHAT. Take the small value at address , and ask: what if I read only 1 byte at address 100?

  • Little-endian: . Reading byte at gives — the correct value!
  • Big-endian: . Reading byte at gives — wrong; the hides at .

WHY. In little-endian the byte at the lowest address is always the low-order part, so widening an -bit read to -bit is "free": the extra high bytes already sit at higher addresses. This is one practical reason little-endian is common (see Memory Addressing).

PICTURE. The green arrow reads one box at address . Little-endian's arrow lands on ; big-endian's lands on .

Figure — Endianness (big vs little)

Step 7 — Degenerate & edge cases (never leave a gap)

WHAT & WHY. Every scenario, so nothing surprises the reader:

  1. A single byte (). Then , so big and little give the identical layout . A one-byte value has no endianness.
  2. A byte array / string . Each element is its own one-byte scalar. So H then i on both machines — array element order is not endianness. (See Pointers and Type Punning.)
  3. The value . All bytes are ; both conventions store — indistinguishable.
  4. Bits inside a byte are never touched. stays ; only whole boxes move.

PICTURE. Left: the case, both rules agree. Right: the string case, H/i in the same order on both — with a red "✗ not endianness" stamp.

Figure — Endianness (big vs little)

Step 8 — The detection trick, derived

WHAT. Store int x = 1;, then read the single byte at the lowest address.

  • If that byte is little-endian.
  • If that byte is big-endian.

WHY. The value has exactly one nonzero byte: its LSB is , and . So the location of the lone byte reveals the rule. Little-endian puts LSB (the ) at the lowest address; big-endian buries it at the highest.

PICTURE. Both layouts of the number ; a pointer reads box and the result ( vs ) labels each machine.

Figure — Endianness (big vs little)

The one-picture summary

Everything at once: the number split by significance, the reconstruction weights, and the two storage orders side by side — big-endian straight-down, little-endian crossed-over.

Figure — Endianness (big vs little)
Recall Feynman retelling of the whole walkthrough

A number too fat for one mailbox gets sliced into four byte-chunks. The chunks aren't equal: the leftmost is the "big" chunk (worth ), the rightmost the "ones" chunk (worth ) — that's what the formula measures, dividing away low chunks and keeping the bottom one. Now line up four mailboxes. Big-endian drops the big chunk in the first mailbox, so a memory dump reads like a normal number. Little-endian drops the little (ones) chunk first, which crosses the wires but means the first mailbox is always the low-order part — so reading just one byte gives you the small value for free. A one-byte value or a text string looks identical either way, because there's nothing to reorder. And the classic test: store the number ; its only nonzero byte is — whichever mailbox that lands in tells you the machine's rule. Same number every time; only the mailbox-order changes.


Recall

Why does a single-byte value have no endianness?
With , the offset formula gives , so big and little store the identical byte at address 0.
In the formula , what does dividing by do?
Shifts away (divides out) the low bytes so byte becomes the lowest remaining one.
Little-endian: byte at offset equals?
(offset equals significance index, LSB at lowest address).
Big-endian: byte at offset equals?
(reversed index, MSB at lowest address).
Why is widening an 8→32-bit read "free" in little-endian?
The lowest address always holds the low-order byte, so the extra high bytes already sit at higher addresses.
Store int 1; byte at lowest address is 0x01 — which endianness?
Little-endian (LSB 0x01 sits at the lowest address).
Is {'H','i'} reordered by endianness?
No — each element is its own 1-byte scalar; array order is unchanged on both machines.

Connections

  • Endianness (big vs little) — parent topic; this page is its picture-by-picture derivation.
  • Data Representation — the weighting used in Steps 2–3.
  • Bitwise Operations — shift = divide by power of two, mask = mod, used to extract bytes.
  • Memory Addressing — byte-addressable boxes and lowest-address ordering.
  • Pointers and Type Punning — reading one byte at the lowest address (detection trick).
  • Network Protocols — big-endian is "network byte order" for multi-byte fields.