# Memory - Byte Order - (Endian-ness) of a Word

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

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

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

Discover More
BOM (byte order mark)

The byte order mark (BOM) is a magic number (header) (Unicode character, feffU+FEFF BYTE ORDER MARK (BOM) It is not a character, but a byte sequence at the beginning of the file. It can be found at the...
Byte Array (multi-byte word)

A byte array is any array of byte. Library represents them generally as a multi-byte word with the possibility to change the endianess. See for instance, the Array Buffer in Javascript To a integer...
CPU - Word

A word is a fixed-sized piece of data processed as a unit by the processor. The word size is defined in the instruction set architecture. The term word is used for a small group of bits that are handled...
Computer - Processor

A processor is a programmable device and has therefore its own instruction set. processor means the same thing than microprocessor Intel 64 and IA-32 processors are little endian machines Graphics...
Computer Storage - Integer Data Type (Binary Data)

In computer, integer are stored in word from 8 to 64 bit. Because CPU manipulates integer data type, they are also sometime called binary data type. Bit Length Two's complement signed Unsigned Float...
Instruction - Fetch

Fetch is a step in the the cycle of an instruction. The processor fetches instructions from the code segment, using a logical address that consists of: the segment selector in the CS register ...
Intel Instruction Interpretation

This section is based on the section 3-1 - interpreting the instruction pages reference of the intel documentation and used the jmp mnemonic as example. Definition: The jmp mnemonic transfers program...
Javascript - Byte Array (ArrayBuffer / DataView)

To manipulate a byte array, in javascript, you have: a ArrayBuffer that represents an array: of fixed amount of bytes (one element = 1 byte) of binary element known as typed object : Int8 / Uint8:...