Beetwise

Big endian and little endian

Endianness sets the order of the bytes of a value in memory.

Big endian puts the most significant byte at the lowest address.

Little endian puts the least significant byte at the lowest address.

Try it

The value 0x1234 in a 16-bit register. Select a bit to change it. Change the bit width or the signed mode to see the effect.

Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·4
Shift
Sign
Bits
Endian
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

Worked example

Store the 16-bit value 0x1234 in memory:

  1. The value has two bytes: 0x12 and 0x34.
  2. In big endian order, memory holds 12 34.
  3. In little endian order, memory holds 34 12.
  4. The value in the register is the same in both cases.

Where this is used

Most desktop processors and the ARM cores in common microcontrollers use little endian order.

Many network protocols use big endian order, which is also called network byte order.

A wrong byte order gives a value that looks random but is in fact reversed.

Points to note

  • Endianness applies to bytes, not to the bits inside a byte.
  • A value of one byte has no byte order. Endianness starts at a bit width of 16.
  • A serial protocol must state its byte order. Two devices with different orders cannot exchange values.

The full tool

The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.

Open the full editor

Questions

Which order does my processor use?
An x86 processor and most ARM cores use little endian order. Check the data sheet for another architecture.
What is network byte order?
Network byte order is big endian. The functions htons and htonl convert a value into this order.
Does endianness change the bits?
No. The bits of the value stay the same. Only the position of each byte in memory changes.