Misplaced Pages

Endianness: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 11:53, 19 September 2003 editMartinHarper (talk | contribs)Autopatrolled, Pending changes reviewers, Rollbackers24,927 editsm rm self link← Previous edit Revision as of 20:29, 22 September 2003 edit undoTakuyaMurata (talk | contribs)Extended confirmed users, IP block exemptions, Pending changes reviewers89,986 edits roughly merged; need actual mergingNext edit →
Line 32: Line 32:
== Additional Resources == == Additional Resources ==
* *
---------
When an integer is represented with multiple bytes, the actual ordering of those bytes in memory, or the sequence in which they are transmitted over some medium, is subject to convention. This is similar to the situation in written languages, where some are written left-to-right, while others are written right-to-left.

Using a 4-byte integer, written as "ABCD", where A is the most significant byte and D is least significant byte, ''big-endian'' convention would store the number in successive memory locations as A (lowest address), then B, then C, finally D, while ''little-endian'' convention would store the bytes in D-C-B-A order.

''Network byte order'' is, by convention, sending the bytes in the order A, then B, etc., onto the medium. It is the responsibility for the transmitting and receiving systems to convert, if necessary, to their internal endian format.

Big-endian numbers are easier to read when debugging a program but less intuitive (because the high byte is at the ''smaller'' address); similarly little-endian numbers are more intuitive but harder to debug. The choice of big-endian vs. little-endian for a CPU design has begun a lot of ]s. Emphasizing the futility of this argument, the very term ''big-endian'' was taken from the Big-Endians of ]'s ]. See the , including the significant essay "On holy wars and a plea for peace", Danny Cohen 1980.

* Processor families that use big-endian storage: ], ], ]
* Processor families that use little-endian format: ], ]
* Processor families that use either (determined by software): ], ], ]
* The PDP family of processors, which were word- rather than byte-addressable, used the unusual pattern of B-A-D-C (that is, byte-swap within words).

Revision as of 20:29, 22 September 2003


Endianness describes the method by which information is stored in a computer's memory, either big-endian or little-endian. Endianness is also referred to as byte sex.

When some computers store a 32-bit integer value in memory, for example 0xDEADBEEF, they store it as bytes in the following order: DE AD BE EF, that is, most significant byte first (that is to say, most significant byte is stored at the lowest byte address in store within this word).

Architectures that follow this rule are called big-endian and include Motorola 68000 and PowerPC.

Other computers store 0xDEADBEEF as EF BE AD DE, that is, least significant byte first. Architectures that follow this rule are called little-endian and include MOS Technologies 6502 and Intel x86.

Some architectures can be configured either way; these include ARM and MIPS.

Still other (generally older) architectures, called middle-endian, may have a more complicated ordering such that the bytes within a 16-bit unit are ordered differently from the 16-bit units within a 32-bit word. For instance, BE EF DE AD. See also NUXI problem.

The Internet Protocol defines a standard "big-endian" network byte order, where binary values are in general encoded into packets, and sent out over the network, most significant byte first. This occurs regardless of the native endianness of the host CPU.

Serial devices also have bit-endianness: the bits in a byte can be sent little-endian (least significant bit first) or big-endian (most significant bit first). This decision is made in the very bottom of the data link layer of the OSI model.

The terms "big-endian" and "little-endian" relate to the conflict over which end to crack an egg in the voyage to Lilliput and Blefuscu from Gulliver's Travels by "Dr. Lemuel Gulliver" (pen name of Jonathan Swift).

byte-sexual

The word bytesexual, said of hardware, denotes willingness to compute or pass data in either big-endian or little-endian format (depending, presumably, on a mode bit somewhere). See also NUXI problem.


This section was originally based on material from FOLDOC, used with permission.

Additional Resources


When an integer is represented with multiple bytes, the actual ordering of those bytes in memory, or the sequence in which they are transmitted over some medium, is subject to convention. This is similar to the situation in written languages, where some are written left-to-right, while others are written right-to-left.

Using a 4-byte integer, written as "ABCD", where A is the most significant byte and D is least significant byte, big-endian convention would store the number in successive memory locations as A (lowest address), then B, then C, finally D, while little-endian convention would store the bytes in D-C-B-A order.

Network byte order is, by convention, sending the bytes in the order A, then B, etc., onto the medium. It is the responsibility for the transmitting and receiving systems to convert, if necessary, to their internal endian format.

Big-endian numbers are easier to read when debugging a program but less intuitive (because the high byte is at the smaller address); similarly little-endian numbers are more intuitive but harder to debug. The choice of big-endian vs. little-endian for a CPU design has begun a lot of flame wars. Emphasizing the futility of this argument, the very term big-endian was taken from the Big-Endians of Jonathan Swift's Gulliver's Travels. See the Endian FAQ, including the significant essay "On holy wars and a plea for peace", Danny Cohen 1980.

  • Processor families that use big-endian storage: SPARC, Motorola 68000, IBM 370
  • Processor families that use little-endian format: x86, VAX
  • Processor families that use either (determined by software): MIPS, DEC Alpha, PowerPC
  • The PDP family of processors, which were word- rather than byte-addressable, used the unusual pattern of B-A-D-C (that is, byte-swap within words).