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; it specifies how the bytes of an object are arranged.
Classification
There are two kinds of byte order: little endian and big endian.
For convenience, consider a variable located at 0x100, of type int, whose hexadecimal value is 0x01234567. Here, 0x01 is the most significant byte, and 0x67 is the least significant byte.
Little Endian
Little endian means that a machine stores an object 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 means that a machine stores an object 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 | .... |
The Difference Between the Two Orders
In fact, neither byte order is inherently better than the other. The names “little endian” and “big endian” come from Gulliver's Travels. In the book, two factions in Lilliput are locked in conflict because they cannot agree on which end of an egg to crack, the little end or the big end. As with that dispute over eggs, the debate over which byte order to choose is non-technical.
However, inconsistent byte order can reverse binary data when it is transmitted between machines with different architectures. To avoid this, network applications use a standard that ensures data is sent according to an agreed-upon network format rather than each machine's internal representation.
Conventional Choices of Byte Order
-
Little endian: x86, ARM processors running Android, iOS, and Windows
-
Big endian: Sun, PPC Mac, Internet