What is Endianness?

Endianness refers to the order in which bytes are arranged in computer memory. This concept is essential for data representation, particularly when dealing with multi-byte data types, and can significantly impact data processing and interoperability between different systems.

The Great Endianness Debate: A Story of Two Cultures

Imagine you have to write the number 1,000 on a form, but the form has four little boxes. How would you write it?

Option A (The "Big-Endian" Culture):
You are methodical. You start from the most significant part. You think: "One thousand." So you write:

[1] [0] [0] [0]
You start with the "big end" (the thousands place).

Option B (The "Little-Endian" Culture):
You are the type to get straight to the point. You start with the smallest, most immediate part. You think: "Zero... zero... zero... one!" So you write:

[0] [0] [0] [1]
You start with the "little end" (the units place).

Both methods ultimately represent "one thousand," but the order in which you write the digits is completely opposite!

This, in a nutshell, is Endianness. It's the convention a CPU uses to store a multi-byte data value in memory.

  • Big-Endian: Stores the most significant byte (the "big" end) at the smallest memory address.

  • Example: How we write numbers and IP addresses. 192.168.1.1 is written with the most significant part (192) first.
  • Little-Endian: Stores the least significant byte (the "little" end) at the smallest memory address.

  • This is what Intel x86/x64 processors (the ones in your laptops) use.

Let's see it in action with a real number.


Live Demonstration in Memory City

Let's store the number 1,000 in our memory city. The hexadecimal representation for 1,000 is 0x000003E8. It's made of four bytes: 00, 00, 03, and E8.

Our starting address is 0x1000.

If our CPU is Big-Endian:
It starts with the biggest byte first.

  • Address 0x1000: [00]
  • Address 0x1001: [00]
  • Address 0x1002: [03]
  • Address 0x1003: [E8]

The order in memory is exactly as we read it: 00 00 03 E8.

If our CPU is Little-Endian (like your computer):
It starts with the smallest byte first.

  • Address 0x1000: [E8] <-- The least significant byte comes first!
  • Address 0x1001: [03]
  • Address 0x1002: [00]
  • Address 0x1003: [00]

The order in memory is reversed: E8 03 00 00.

When the CPU reads from address 0x1000, it knows to take the next 4 bytes and re-assemble them in the correct order for its internal calculations.