Byte ordering refers to how multibyte data, such as 32-bit words, are stored in memory. There are two main byte ordering schemes: Big Endian and Little Endian. The difference lies in the order in which the bytes of a multibyte data type are stored in memory. Let’s explore the differences and then examine the contents of memory in the given scenario.
Big Endian Byte Ordering:
In Big Endian byte ordering, the most significant byte (MSB) is stored at the lowest memory address, and the least significant byte (LSB) is stored at the highest memory address. It is as if we write a number from left to right, with the most significant digit on the left.
Example: Storing the ASCII string “Johnson” in Big Endian byte ordering.
Address: 1000 1001 1002 1003 1004 1005 1006 1007
Data (Hex): 4A XX XX XX 6F XX XX XX
Character: J o h n
In Big Endian, the ASCII characters are stored in successive bytes starting from address 1000. The ASCII value of ‘J’ (the first character of “Johnson”) is 4A, which is stored at address 1000. The ASCII value of ‘o’ is 6F, stored at address 1004. The remaining bytes are unused (indicated by XX).
Little Endian Byte Ordering:
In Little Endian byte ordering, the least significant byte (LSB) is stored at the lowest memory address, and the most significant byte (MSB) is stored at the highest memory address. It is as if we write a number from left to right, with the least significant digit on the left.
Example: Storing the ASCII string “Johnson” in Little Endian byte ordering.
Address: 1000 1001 1002 1003 1004 1005 1006 1007
Data (Hex): XX XX XX XX 4A XX XX XX
Character: J o h n
In Little Endian, the ASCII characters are stored in successive bytes starting from address 1004. The ASCII value of ‘J’ (the first character of “Johnson”) is 4A, which is stored at address 1004. The ASCII value of ‘o’ is 6F, but it is stored in the next byte at address 1005. The remaining bytes are unused (indicated by XX).