Endianness

From Wexos's Wiki
(Redirected from Endian)
Jump to navigationJump to search

In memory, 8 bits are grouped and forms a byte, which a processor then can read from as well as write to. When a processor needs to access multiple bytes which is stored together (such as a 16-bit value), then the order it reads or writes the data is important. The endianness of a processor, also known as endian, describes which order bytes are stored in memory.

Big endian and little endian are used to seperate the order. Big endian stores the most significant byte at the lowest address, while little endian stores the reverse order, most significant byte is stored at the highest address. For instance, the value 4660 = 0x1234 is stored as 12 34 in big endian systems, while it's stored as 34 12 in little endian systems.

In Files

Generally, file formats use the same endianness as the processor. When this is the case, a game can allocate memory of the same size as the file, read the whole file at once, and have to do minimal parsing. When not, the game has to parse the data, which gives worse performance. Some games supports both endianness on the same platform. This can be done by either parsing the data, or reversing memory.

Byte-Order-Mark

A byte-order-mark (BOM) is a magic number which is used to specify the endianness of a file. Commonly it is a 16-bit value which is either FE FF (big endian) or FF FE (little endian). This is commonly used in text files, to specify the order of the character encoding.

External Links