Endianness

From Helpful

This article/section is a stub — probably a pile of half-sorted notes and assertions some of which may well be wrong, and not verified as a whole. Feel free to add or refine.

Common meaning

Endianness usually refers to the in-memory order of the parts in a larger structure.

You can generally assume endianness refers specifically to byte order, which refers to the order of the bytes in a multi-byte structure - how it is actually stored if you were to look at that memory at a byte level instead of the implicitly correct interpretation of the thing that put it there in the first place.


When endianness refers to other concepts, this is usually explicitly mentioned, understood from context, or the term isn't used at all.

For example, it sometimes refers to bit order - the storage/transfer order of bits within bytes (e.g. in various networking details, and some bitwise calculations). However, this only matters to bit-level operations/addressing, so generally matters only at the hardware level, and fairly rarely in programming.


In unusual architectures it can have different meanings yet. For example, if a machine has 16-bit memory units (instead of the much more usual 8-bit units), the endianness concept is the same, same but the units that can appear in different orders are those 16-bit words.

(You can even argue about the order of bytes in those 16-bit cells -- however, this is usually entirely moot as in most cases, you will only ever see values through the external interface that gives you 16-bit values.)


Little-endian, Big-endian, LSB, MSB

This article/section is a stub — probably a pile of half-sorted notes and assertions some of which may well be wrong, and not verified as a whole. Feel free to add or refine.
  • Little-endian: increasing numeric significance with increasing memory addresses (or, in other contexts, time)
  • Little-endian architectures store the Least Significant Byte (LSB) first. They include the x86 line of processors (Intel, AMD, most of the world)
  • In byte archiectures also known as LSB


  • Big-endian: decreasing significance; the most-significant byte first.
  • Big-endian architectures store the Most Significant Byte (MSB) first (in the lowest memory location), and includes the Motorola line of processors (e.g. pre-Intel Macintosh)
  • In byte architectures also known as MSB


  • 'Network byte order' refers to MSB


One way to illustrate the difference is using an integer, say, 287454020. Rather, consider it as hex, 0x11223344 -- because in hex, each two characters represent a byte.

  • In MSB, the four memory bytes that store it contain 0x11, 0x22, 0x33, 0x44
  • In LSB, it is 0x44, 0x33, 0x22, 0x11


Less usual cases

This article/section is a stub — probably a pile of half-sorted notes and assertions some of which may well be wrong, and not verified as a whole. Feel free to add or refine.

Some architecture designs are bi-endian -- allow handling of both endiannesses.

In some cases, this is handled by transparent hardware conversion, meaning that the non-native order is a smidge slower than the native order as the (very simple, but still present) conversion has to happen.

In rarer cases, the hardware will have real, equal support for both, to avoid a speed hit when something of the non-hardware-natural endianness is used.


A separate issue comes in with hardware. For example, when Apple added PCI slots, most graphics cards wouldn't actually work in them because Apple basically ignored the endianness of the PC cards's implementations. The only cards that would work were those that were implemented to support Macs. (Whether this was strategic or stupid may be hard to tell)


Mixed endianness can also be said to exist -- although this is not a strictly defined or agreed-on term.

It usually describes architectures which deal with non-byte-sized units in memory addressing. For example, storing a 32-bit int in a 16-bit-word architecture could lead to 0x11 0x22 0x33 0x44 -- or 0x33 0x44 0x11 0x22, depending on architectural details.