Endianness

From Academic Kids

When integers or any other data are represented with multiple bytes, there is no unique way of ordering those bytes in memory or in transmission over some medium, so the order is subject to arbitrary convention, called endianness. This is actually somewhat similar to the situation in different written languages, where some are written left-to-right, while others are written right-to-left.

There seems to be no significant advantage in using one way over the other. In addition, the endianness does not matter when dealing with a sequence of single bytes. This is the case with strings encoded in ASCII and similar codes, where each byte corresponds to a single character. Strings encoded with unicode UTF-16 or UTF-32 are affected by endianness, because each set of two or four bytes represents a single character.

The two main types of endianness are termed big-endian and little-endian. Endianness is also referred to as byte order or byte sex.

Contents

Endianness in computers

Detailed description

When some computers store a 32-bit integer value in memory, for example 0x4A3B2C1D (in hexadecimal notation), they store it as bytes in the following order: 4A 3B 2C 1D. That is, the most significant byte (also known as the msb, which is 4A in our example) is stored at the memory location with the lowest address, the next byte in significance, 3B, is stored at the next memory location and so on.

Architectures that follow this rule are called big-endian (mnemonic: "big end first") and include Motorola 68000, SPARC and System/370.

Other computers store the value 0x4A3B2C1D as 1D 2C 3B 4A, that is, least significant ("littlest") byte (also known as lsb) first. Architectures that follow this rule are called little-endian (mnemonic: "little end first") and include the MOS Technology 6502, Intel x86 and DEC VAX.

In other words, contrary to what you might first think endianness does not denote what the value ends with when stored in memory, but rather what end it begins with.

Note that the stated mnemonics are not the origin of the terms, see below.

Some architectures can be configured either way; these include ARM, PowerPC (but not the PPC970/G5), DEC Alpha, MIPS, PA-RISC and IA64). The word bytesexual or bi-endian, 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). Many of these architectures can be switched via software to default to a specific endian format (usually done when the computer starts up); however, on some architectures the default endianness is selected by some hardware on the motherboard and sometimes even cannot be changed by software (e.g., the DEC Alpha, which runs only in big-endian mode on the Cray T3E).

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, 0x4A3B2C1D is stored as 3B 4A 1D 2C. Middle-endian architectures include the PDP-11 family of processors. The format for double-precision floating-point numbers on the VAX is also middle-endian. In general, these complex orderings are more confusing to work with than consistent big- or little-endianness.

Endianness also applies in the numbering of the bits within a byte or word. In a consistently big-endian architecture the bits in the word are numbered from the left, bit zero being the most significant bit and bit 7 being the least significant bit in a byte. The favored bit endianness depends somewhat on where the computer users expect the binary point to be located in a number. It seems most intuitive to number the bits in the little-endian order if the byte is taken to represent an integer. In this case the bit number corresponds to the exponent of the numeric weight of the bit. However, if the byte is taken to represent a binary fraction, with the binary point to the left of the most significant bit, then the big-endian numbering convention is more convenient.

To summarize, here are the default endian-formats of some common computer architectures:

Portability issues

Endianness has grave implications in software portability. For example, in interpreting data stored in binary format and using an appropriate bitmask, the endianness is important because different endianness will lead to different results from the mask.

Writing binary data from software to a common format leads to a concern of the proper endianness. For example saving data in the BMP bitmap format requires little endian integers - if the data are stored using big endian integers then the data will be corrupted since they do not match the format.

The OPENSTEP operating system has software that swaps the bytes of integers and other C datatypes in order to preserve the correct endianness, since software running on OPENSTEP for PA-RISC is intended to be portable to OPENSTEP running on Mach/i386.

In Unicode a Byte Order Mark (BOM) of between 2 and 4 bytes is used at the beginning of a string to denote its endianness.

Endianness in communications

In general, the NUXI problem is the problem of transferring data between computers with differing byte order. For example, the string "UNIX", packed two bytes per 16-bit word integer, might look like "NUXI" on a machine with a different "byte sex". The problem is caused by the difference in endianness. The problem was first discovered when porting an early version of Unix from PDP-11 (a middle-endian architecture) to a big-endian IBM architecture.

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.

Endianness in date formats

Endianness is simply illustrated by the different manners in which countries format calendar dates. For example, in the United States and a few other countries, dates are commonly formatted as Month; Day; Year (e.g. "May 24th, 2006" or "5/24/2006"). This is a middle-endian order.

In most of the world's countries, including all of Europe except Latvia and Hungary, dates are formatted as Day; Month; Year (e.g. "24th May, 2006" or "24/5/2006" or "24/5-2006"). This is little-endian.

China and the ISO 8601 International formal standard ordering for dates displays them in the order of Year; Month; Day (e.g. "2006 May 24th", or, more properly, "2006-05-24"). This is big-endian.

The latter two ordering schemes lend themselves to straightforward computerized sorting of dates (note, however, that this simplicity in sorting, most often based on ASCIIbetical text string order, requires that the nine first dates of each month and the nine first months of the year be numbered '01', '02', ... , '09').

Discussion, background, etymology

Big-endian numbers are easier to read when debugging a program. Some think they are less intuitive because the most significant byte is at the smaller address. Some think they are less confusing because the significance order is the same as the order of normal textual character strings in the computer, just as in non-computer text (see below). A person's preference usually is based on which convention was studied first and on which one the person's mental models were built.

The choice of big-endian vs. little-endian has been the subject of a lot of flame wars. Emphasizing the futility of this argument, the very terms big-endian and little-endian were taken from the Big-Endians and Little-Endians of Jonathan Swift's novel Gulliver's Travels, two groups of people in conflict over which end of an egg to crack in the voyage to Lilliput and Blefuscu.

See the Endian FAQ (http://www.rdrop.com/~cary/html/endian_faq.html), including the significant essay "On Holy Wars and a Plea for Peace" (http://www.rdrop.com/~cary/html/endian_faq.html#danny_cohen) by Danny Cohen (1980).

The written system of arabic numerals is used world-wide and is such that the most significant digits are always written to the left of the less significant ones. In languages that write text left-to-right, this system is therefore big-endian, in languages that write right-to-left, this numeral system is little-endian. The spoken numeral system in English is big endian (with minor exceptions: we say "seventeen" instead of "ten-seven"). German and Dutch are also mainly big-endian, with an exception for the multiples-of-ten, e.g. 376 is pronounced as "Dreihundertsechsundsiebzig", i.e. "three hundred six-and-seventy".

Little-endian ordering has been used in compiling reverse dictionaries, where the entries begin, for example, with "a, aa, baa, ..." and end, for example, with "... buzz, abuzz, fuzz."

There seems to be some confusion about how the word endianness should be spelled. The two major variants are endianness and endianess. There are even some documents containing both variants. While neither of the two forms appears in current (non-computing) dictionaries, it appears that the former follows the pattern of similar words such as "barren" and "barrenness". Thus, endianness is generally more accepted and is used in this article.

External links


This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.
de:Byte-Reihenfolge

fr:Endianness it:Endianess ja:エンディアン pl:Kolejność bajtów

Navigation

Academic Kids Menu

  • Art and Cultures
    • Art (http://www.academickids.com/encyclopedia/index.php/Art)
    • Architecture (http://www.academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (http://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (http://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools