Endian

From Custom Mario Kart
Jump to: navigation, search

Endianness

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 these bytes are stored in 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 are generally stored in consecutive memory addresses (e.g. a 32-bit integer would need 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.

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

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 the Wii[1] is an IBM PowerPC[2], which stores data using the big-endian format. On the other hand, the processors found in most PCs use little-endian. This means to view and edit Wii data (particularly numbers) on a PC, the byte order must be reversed. Many tools support this reversing.

References

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

External links

Wikipedia article on endianness