Table of Contents

About

Storage of a word in memory of more than one byte (ie byte array)

If each memory address of the memory array can store only a single byte, you need to split the word in multi-part one byte long.

This part are stored in memory in an order called Endianness:

Endianness only makes sense when you are breaking up a multi-byte word, and attempting to store the bytes at consecutive memory locations.

Type

Big

Little Endian means the bytes of a word are numbered starting from the most significant byte.

Aka if the first byte store the most significant byte (MSB): big endian - natural order - aka network (byte) order

Example given for the storage of the hexadecimal word 92AB15CD

Address Value (In Hexadecimal)
1000 92
1001 AB
1002 15
1003 CD

Little

Little Endian means the bytes of a word are numbered starting from the least significant byte

If the first byte store the least significant byte (LSB): little endian

Example given for the storage of the hexadecimal word 92AB15CD

Address Value (In Hexadecimal)
1000 CD
1001 15
1002 AB
1003 92

Intel 64 and IA-32 processors are little endian machines.

CPU

Different instruction set architecture (ISAs) (and then machine) use different endianness.

  • big endian: Motorolas and Suns
  • little endian: DEC and IBMs

Problem with endianness

If you (send|transfer) data from a source machine of one endianness to a target machine of the opposite endianness, the target machine will read badly the data in reversed order.

Solution

The solution is to send 4 byte quantities using network byte order which is arbitrarily picked to be big endian. If the target machine has the same endianness as network byte order, then great, no change is needed. If not, then you must reverse the bytes.

History of Endian-ness

In the book “Gulliver's Travels”, Jonathan Swift talks about how:

  • certain people prefer to eat their hard boiled eggs from the little end first (thus, little endian),
  • while others prefer to eat from the big end (thus, big endians)

and how this lead to various wars.

Of course, the point was to say that it was a silly thing to debate over, and yet, people argue over such trivialities all the time.

For example:

  • should braces line in parallel or not?
  • vi or emacs?
  • UNIX or Windows

Documentation / Reference