Little endian v/s Big endian

Little endian and big endian are two ways of storing multibyte data types (such as integers and floating-point numbers) in computer memory.

In little endian byte order, the least significant byte of a multibyte value is stored at the lowest memory address, while the most significant byte is stored at the highest memory address. This means that when we read a multibyte value from memory, we start with the least significant byte and then move on to the next byte with increasing significance. Little endian is used by some processors, such as x86 and ARM.

In big endian byte order, the most significant byte of a multibyte value is stored at the lowest memory address, while the least significant byte is stored at the highest memory address. This means that when we read a multibyte value from memory, we start with the most significant byte and then move on to the next byte with decreasing significance. Big endian is used by some other processors, such as PowerPC and SPARC.

For example, consider the 32-bit integer value 0x12345678.

In little endian byte order, this value would be stored in memory as: LSB is stored at lowest address first.

 Address    |  Value
-------------|---------
0x10000000   |   0x78
0x10000001   |   0x56
0x10000002   |   0x34
0x10000003   |   0x12

In big endian byte order, the same value would be stored in memory as: MSB is stored at lowest address first.

  Address    |  Value
-------------|---------
0x10000000   |   0x12
0x10000001   |   0x34
0x10000002   |   0x56
0x10000003   |   0x78

When transferring data between systems that use different byte orders, it is important to convert the byte order to ensure that the data is interpreted correctly. This can be done using functions such as ntohl() and htonl() in C, which convert 32-bit integers between network byte order (big endian) and host byte order (either little endian or big endian depending on the system).

Leave a comment