From Wikipedia, the free encyclopedia
  (Redirected from Byte order)
Jump to: navigation, search

Endianness is the ordering or sequencing of bytes of a word of digital data in computer memory storage or during transmission. Words may be represented in big-endian or little-endian manner. Big-endian systems store the most-significant byte of a word at the smallest memory address and the least significant byte at the largest. A little-endian system, in contrast, stores the least-significant byte at the smallest address.[1]

Both forms of endianness are in widespread use in digital electronic engineering. The initial choice of endianness of a new design is often arbitrary, but later technology revisions and updates perpetuate the existing endianness and many other design attributes to maintain backward compatibility. As examples, the Intel x86 processor represents a common little-endian architecture, and IBM z/Architecture mainframes are big-endian processors. The designers of these two processor architectures decided on endianness in the 1960s and 1970s in their initial product introductions.

Big-endian representation is the most common convention in data networking; fields in the protocols of the Internet protocol suite, such as IPv4, IPv6, TCP, and UDP, are transmitted in big-endian order. For this reason, big-endian byte order is also referred to as network byte order. Little-endian storage is popular for microprocessors in part due to significant historical influence on microprocessor designs by Intel Corporation. Mixed forms also exist, for instance the ordering of bytes within a 16-bit word may differ from the ordering of 16-bit words within a 32-bit word. Such cases are sometimes referred to as mixed-endian or middle-endian. There are also some bi-endian processors which can operate either in little-endian or big-endian mode.



Endianness may be demonstrated by a decimal number that is written and read in positional notation (place-value notation). Assuming a writing system that displays numbers written left to right, the left-most position is analogous to the smallest address of memory used, and right-most position the largest. For example, the number one hundred twenty three is written 123, with the hundreds-digit 1 being the left-most. Anyone who reads this number also knows that the left-most digit has the biggest place value. This is an example of a big-endian convention taken from daily life. The little-endian way of writing the same number would be to place the digit 3 in the left-most position: 321. A person following place-value notation who is not alerted of this special ordering would assume the number was three hundred and twenty one. Endianness in computing is similar, but it applies to the ordering of bytes in memory or during transmission.

The illustration (right) shows an example using the data word "0A 0B 0C 0D", which is a set of four bytes written using left-to-right positional, hexadecimal notation, and the four memory locations with addresses a, a+1, a+2 and a+3. In a big-endian system, byte 0A is stored in a, 0B in a+1, 0C in a+2 and 0D in a+3. In a little-endian system, the order is reversed, storing 0D at memory address a, 0C at a+1, 0B at a+2, and 0A at address a+3.


Before the development of microprocessors, most computers used a big-endian approach, but a notable exception was the PDP-11. The Datapoint 2200 was designed using simpler bit-serial logic in which little-endian address and data formats facilitate carry propagation. When Intel implemented the 8008 for Datapoint, they kept the little-endian architecture. However, Datapoint never used the 8008 chip, using an MSI equivalent implementation as Intel was unable to deliver the 8008 in time. The little-endian format in this case was actually unnecessary.[2][3]

Dealing with data of different endianness is sometimes termed the NUXI problem.[4] This terminology alludes to the byte order conflicts encountered while adapting UNIX, which ran on the little-endian PDP-11, to a big-endian computer such as the IBM Series/1. One of the first programs converted was supposed to print out Unix, but on the Series/1 it printed nUxi instead.[5] Unix was one of the first systems to allow the same code to run on, and transfer data between, platforms with different internal representations.


In 1726, Jonathan Swift described in his satirical novel Gulliver’s Travels tensions in Lilliput and Blefuscu: whereas royal edict in Lilliput requires cracking open one's soft-boiled egg at the small end, inhabitants of the rival kingdom of Blefuscu crack theirs at the big end, giving them the moniker Big-endians.[6][7] The terms little-endian and endianness have a similar intent.[8]



Endianness of hardware[edit]

Computer memory consists of a sequence of storage cells. Each cell is identified in hardware and software by its memory address. If the total number of storage cells in memory is n, then addresses are enumerated from 0 to n-1. Computer programs often use data structures of fields that may consist of more data than is stored in one memory cell. For the purpose of this article where its use as an operand of an instruction is relevant, a field consists of a consecutive sequence of bytes and represents a simple data value. In addition to that, it has to be of numeric type in some positional number system (mostly base-10 or base-2 — or base-256 in case of 8-bit bytes).[9] In such a number system the "value" of a digit is determined not only by its value as a single digit, but also by the position it holds in the complete number, its "significance". These positions can be mapped to memory mainly in two ways:[10]

  • decreasing numeric significance with increasing memory addresses (or increasing time), known as big-endian[11]

The Intel x86 and x86-64 series of processors use the little-endian format, and for this reason, the little-endian format is also known[by whom?] as the "Intel convention". Other well-known little-endian processor architectures are the 6502 (including 65802, 65C816), Z80 (including Z180, eZ80 etc.), MCS-48, DEC Alpha, Altera Nios II, Atmel AVR, VAX, and, largely, PDP-11. The Intel 8051, contrary to other Intel processors, expects 16-bit addresses in big-endian format, except for the LCALL instruction whose target address is stored in little-endian format.[12]



Bi-endian hardware[edit]






Floating-point and endianness[edit]





Calculation order[edit]


Mapping multi-byte binary values to memory[edit]

Big-Endian Little-Endian
C-type name initial value memory at offset memory at offset
int32_t longVar = 168496141; 0Ah 0Bh 0Ch 0Dh 0Dh 0Ch 0Bh 0Ah
int16_t shortVar = 3085; 0Ch 0Dh 0Dh 0Ch
A simple way to remember is "In Little Endian, the Least significant byte goes into the Lowest-addressed slot".

Let us agree to understand the orientation left to right in memory as increasing memory addresses − as in the table to the left. Furthermore, the hex value 0x0a0b0c0d is defined to be the value 168496141 in the usual (and big-endian style) decimal notation. If you map this value as a binary value to a sequence of 4 bytes in memory in big-endian style, you are writing the bytes from left to right in decreasing significance: 0Ah at +0, 0Bh at +1, 0Ch at +2, 0Dh at +3. However, on a little-endian system, the bytes are written from left to right in increasing significance, starting with the one's byte: 0Dh at +0, 0Ch at +1, 0Bh at +2, 0Ah at +3. If you write a 32-bit binary value to a memory location on a little-endian system and after that output the memory location (with growing addresses from left to right), then the output of the memory is reversed (byte-swapped) compared to usual big-endian notation. This is the way a hexdump is displayed: because the dumping program is unable to know what kind of data it is dumping, the only orientation it can observe is monotonically increasing addresses. The human reader, however, who knows that he is reading a hexdump of a little-endian system and who knows what kind of data he is reading, reads the byte sequence 0Dh,0Ch,0Bh,0Ah as the 32-bit binary value 168496141, or 0x0a0b0c0d in hexadecimal notation. (Of course, this is not the same as the number 0D0C0B0Ah = 0x0d0c0b0a = 218893066.)

Examples of storing the value 0A0B0C0Dh in memory[edit]





Atomic element size 8-bit[edit]

address increment 1-byte (octet)
increasing addresses  →
0Ah 0Bh 0Ch 0Dh


Atomic element size 16-bit[edit]

increasing addresses  →
0A0Bh 0C0Dh




Atomic element size 8-bit[edit]

address increment 1-byte (octet)
increasing addresses  →
0Dh 0Ch 0Bh 0Ah


Atomic element size 16-bit[edit]

increasing addresses  →
0C0Dh 0A0Bh


When organized by byte addresses[edit]

Byte addresses increasing from right to left


With 8-bit atomic elements:

←  increasing addresses
0Ah 0Bh 0Ch 0Dh


With 16-bit atomic elements:

←  increasing addresses
0A0Bh 0C0Dh



←  increasing addresses
"Y" "A" "R" "X"


←  increasing addresses
"AY" "XR"




increasing addresses  →
0Bh 0Ah 0Dh 0Ch



Endianness in networking[edit]

Many IETF RFCs use the term network order, meaning the order of transmission for bits and bytes over the wire in network protocols. Among others, the historic RFC 1700 (also known as Internet standard STD 2) has defined the network order for protocols in the Internet protocol suite to be big-endian, hence the use of the term "network byte order" for big-endian byte order; however, not all protocols use big-endian byte order as the network order.[15]


The telephone network has always sent the most significant part first, the area code.[16]



Endianness in files and byte swap[edit]









  1. storing the data always in one fixed endianness, or




/* C function to change endianness for byte swap in an unsigned 32-bit integer */

uint32_t ChangeEndianness(uint32_t value)
    uint32_t result = 0;
    result |= (value & 0x000000FF) << 24;
    result |= (value & 0x0000FF00) << 8;
    result |= (value & 0x00FF0000) >> 8;
    result |= (value & 0xFF000000) >> 24;
    return result;

Bit endianness[edit]

Bit numbering is a similar concept to endianness in bit-level systems. Bit or bit-level endianness refers to the transmission order of bits over a serial medium. Usually that order is transparently managed by the hardware and is the bit-level analogue of little-endian (low-bit first), as in RS-232, Ethernet, and USB. Some protocols use the opposite ordering (e.g. Teletext, I²C, and SONET and SDH[19]). As bit ordering is usually only relevant on a very low level, terms like LSB first and MSB first are more descriptive for bit order than the concept of endianness.



  12. ^ http://www.keil.com/support/man/docs/c51/c51_xe.htm
  13. ^ "Floating point formats". 
  16. ^ "Webster's New World Telecom Dictionary". 

Further reading[edit]

External links[edit]
