Endianness

From SEGGER Knowledge Base
Jump to navigation Jump to search

Endianness is the term used to describe data byte order. Big-endian means data is being sent or stored with the most significant byte (MSB) first. Little-endian means data is sent with the least significant byte (LSB) first.

A CPU always has endianness, even 8-bit CPUs. All CPUs store data in units larger than single bytes. The stored value cannot be considered on a byte-by-byte basis. If the first byte is the LSB, then the CPU is said to be little-endian. If the first byte is the high-order byte, it is said to be big-endian.

Example:
Let's look at a 32-bit CPU, storing the value 0x12345678 in its memory: (memory shown in hex)
The big big-endian format would look like this: 12 34 56 78; the little-endian format would look like this: 78 56 34 12.

For most CPUs, endianness is fixed by design. For these CPUs, the little-endian format is more popular. All x86 CPUs use the little-endian format. On ARM processors, the endianness is selectable by the chip designer, but in reality, again, a vast majority of CPUs have a little-endian format, making it the de-facto standard. Motorola processors such as Power-PC use the big-endian format.

Internet

On the Internet, byte order is big-endian. This means that little-endian processors are at a slight disadvantage, as they need to swap endianness each time they write to a packet to be sent, or read from a packet received or protocol information.