What is endianness?

Endianness specifies the order in which the bytes of data are stored/processed by a computer.

For example, let's consider a variable which is of 4bytes and in the memory it looks like as shown below.

When we access the variable, all the 4 bytes of data will be fetched from the memory and the resultant value will be computed. The question is, in which order the data is fetched from the memory? Is it from lower address to highest address or vice versa. Endianness defines in which order the data has to be interpreted. Computers follow two types of endianness.

  • Little Endian
  • Big Endian

Little Endian

In little endian computers, the data is always stored from lower address to higher address i.e. LSB is always present at the lower address and MSB is at the higher address.

For example

  • x86 and x64 architecture machines use little endian.

Big Endian

In Big endian computers, the data is stored from higher address to lower address i.e. MSB is always present at lower address and LSB is at the higher address

For example

  • Atmel AVR32 and OpenRISC use big endian.
  • Networking protocols such as TCP, UDP, and ipv4, v6 uses this format.