Skip to content

Endianness

This page briefly introduces the concept and classification of byte order.

Introduction

Byte order is the storage rule for program objects that span multiple bytes, indicating the arrangement method of bytes for an object.

Classification

There are two types of byte order: little-endian and big-endian.

For convenience, the following example uses a variable located at 0x100, of type int, with a hexadecimal value of 0x01234567. Here, 0x01 is the most significant byte, and 0x67 is the least significant byte.

Little-Endian

Little-endian refers to the machine's choice to store objects in memory from the least significant byte to the most significant byte.

The variable mentioned above is represented as follows:

.... 0x100 0x101 0x102 0x103 ....
.... 67 45 23 01 ....

Big-Endian

Big-endian refers to the machine's choice to store objects in memory from the most significant byte to the least significant byte.

The variable mentioned above is represented as follows:

.... 0x100 0x101 0x102 0x103 ....
.... 01 23 45 67 ....

Differences Between the Two Orders

In fact, there is no inherent superiority or inferiority between these two byte orders. The names "little-endian" and "big-endian" originate from the book Gulliver's Travels. In the story, two factions in Lilliput wage endless wars because they cannot agree on whether to crack an egg from the little end or the big end. Just like the egg-cracking debate, the choice of byte order is a non-technical argument.

Of course, inconsistency in byte order can cause binary data to be reversed when transmitted between different types of machines. To avoid this, network applications have established a standard to ensure that data is sent using the agreed-upon network standard rather than the internal representation of different machines.

Conventions for Order Selection

  • Little-endian: x86, ARM processors running Android, iOS, and Windows

  • Big-endian: Sun, PPC Mac, Internet