In computer memory, data is byte-addressable, meaning that each byte in memory has an associated address. Endianness, on the other hand, pertains to the order of bytes in memory. This byte ordering can occur in two ways: Little endian & Big endian

The term endian is derived from a story in Gulliver’s Travels, where there were two kinds of people: one group cracked their eggs at the smaller end, and the other group cracked their eggs at the larger end.

Note: When storing only one byte of data in memory, endianness is not relevant.

Endianness becomes significant when, for instance, we want to store a 4-byte (32-bit) integer value in memory. In this case, four consecutive bytes in memory are required, and that’s where byte ordering matters.

Let’s consider an example: Suppose we want to store the hexadecimal value 0xaabbccdd in memory. The most significant byte (MSB) of this value is aa, and the least significant byte (LSB) is dd.

In little endian format, it would be stored as: dd cc bb aa In big endian format, it would be stored as: aa bb cc dd

Endianness is unnecessary when storing strings because the order of characters in a string matters, and each character occupies 1 byte.

Here is another example:

endianness example