Endian

From Custom Mario Kart
Revision as of 00:10, 10 December 2016 by Wiimm (talk | contribs) (better place for NBO)
Jump to navigation Jump to search

Endianess

In computing, memory commonly stores binary data by splitting it into 8 bit units (bytes). When a data word uses multiple such units, the order of storing these bytes into memory becomes important. The terms endian and endianness, refer to how bytes of a data word are ordered within memory.

Each byte of memory is associated with an index, called its address, which indicates its position. Bytes of a single data word (such as a 32 bit integer datatype) are generally stored in consecutive memory addresses (a 32 bit integer needs 4 such locations). Big-endian systems are systems in which the most significant byte of the word is stored in the smallest address given and the least significant byte is stored in the largest. In contrast, little endian systems are those in which the least significant byte is stored in the smallest address. Say the data word was "0A 0B 0C 0D" (a set of 4 bytes) and memory addresses starting at a with offsets 0, 1, 2 and 3 are given. Then, in big endian systems, byte 0A is placed in offset 0, 0B in 1, 0C in 2 and 0D in 3. In little-endian systems, the order is the reverse of it.

more info at Wikipedia

The network byte order is big endian. This means, that nearly all internet protocols including IP (also called TCP/IP) use big endian data members.

Byte Order Mark

The Byte Order Mark (or BOM) is the Unicode character U+FEFF. It is used to detect the byte order of files. In text files it is placed as the very first character and in binary files as member of the file header.

For big endian files, the first byte is 0xFE and the second 0xFF. For little endian files the first byte is 0xFF followed by 0xFE.

Nintendo Wii

The main processor (CPU) of Nintendo Wii[1] is a IBM PowerPC[2]. The CPU itself is a big endian system. So by the Wii supported file formats store data as big endian.

Current PC

Many PC including Windows, Linux and modern Mac are based on Intel or AMD x86 CPUs. And these are little endian CPUs. This means, for viewing and editing data and especially numbers (integer or floating point) the byte order must be reversed. Many tools support this reversing.

References

  1. Wikipedia: Nintendo Wii
  2. Wikipedia: CPU PowerPC