Byte Order

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:

....0x1000x1010x1020x103....
....67452301....

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:

....0x1000x1010x1020x103....
....01234567....

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

This content comes from OI Wiki: Byte Order. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.