Endianness is a computer science term that describes how data is stored. Specifically, it defines which end of a multi-byte data type contains the most significant values. The two types of endianness are big-endian and little-endian.
Big-endian is the most common way to store binary data. It places the most significant (or largest) value first, followed by less significant values. For example, the big-endian representation of the integer 123 places the hundreds value (1) first, followed by the tens value (2), then the ones value (3), or .
Little-endian stores the least-significant value first, followed by increasingly more significant values. For example, the number 123 in little-endian notation is . The text string "ABC" is represented as [CBA].
In most cases, developers do not have to specify endianness since the compiler generates the correct type of data for a specific platform. However, a program may need to process external input, such as a file format that stores data with a different endianness. In this case, the data must be converted from little-endian to big-endian or vice versa.
Converting endianness is not as simple as reversing the data. The bytes, rather than the bits, must be reversed. In other words, each byte (or block of eight bits) must remain the same, but the order of the bytes is changed. This can be explained using the hexadecimal or binary representation of data.
For example, the integer 41,394 is represented in big-endian notation as:
Converting this data to little-endian does not reverse the data, but rather the individual bytes within the data. Hexadecimal uses two digits to represent each byte – [A1][B2], while binary uses eight digits – .
Therefore, the little-endian representation of 41,394 is:
NOTE: Some processors can fetch data as either big-endian or little-endian with no conversion required. This is called bi-endian data access.
Updated: September 27, 2019