memorycpu-architectureendiannessdata-representation

Little Endian vs. Big Endian architectures


I've a question it is a kind of disagreement with a university professor, about Endianness, So I did not find any mean to solve this and find the right answer but asking and open a discussion in Stack Overflow community.

Let's say that we have this number (hex)11FF1 defined as an integer, for example in C++ it will be like : int num = 0x11FF1, and I say that the number will be presented in the memory in a little endian machine as :

 addr[0] is f1   addr[1] is 1f   addr[2] is 01   addr[3] is 00
 in binary : 1111 0001   0001 1111   0000 0001   0000 0000

as the compiler considers 0x11ff1 as 0x0001ff1 and considers also 00 as the 1st byte and 01 as the 2nd byte and so on, and for the Big Endian I believe it will look like:

 addr[0] is 00   addr[1] is 01   addr[2] is 1f   addr[3] is f1
 in binary : 0000 0000   0000 0001   0001 1111   1111 0001

but he has another opinion, he says :

Little Endian

Little Endian in the professor view

Big Endian:

Big Endian in the professor view

Actually I don't see anything logical in his representation, so I hope the developers Resolve this disagreement, Thanks in advance.


Solution

  • Your hex and binary numbers are correct.

    Your (professor's?) French image for little-endian makes no sense at all, none of the 3 representations are consistent with either of the other 2.

    73713 is 0x11ff1 in hex, so there aren't any 0xFF bytes (binary 11111111).
    In 32-bit little-endian, the bytes are F1 1F 01 00 in order of increasing memory address.
    You can get that by taking pairs of hex digits (bytes / octets) from the low end of the full hex value, then fill with zeros once you've consumed the value.

    It looks like they maybe padded the wrong side of the hex value with 0s to zero-extend to 32 bits as 0x11ff1000, not 0x00011ff1. Note these are full hex values of the whole number, not an attempt to break it down into separate hex bytes in any order.

    But the hex and binary don't match each other; their binary ends with an all-ones byte, so it has FF as the high byte, not the 3rd byte. I didn't check if that matches their hex in PDP (mixed) endian.

    They broke up their hex column into 4 byte-sized groups, which would seem to indicate that it's showing bytes in memory order. But that column is the same between their big- and little-endian images, so apparently that's not what they're doing, and they really did just extend it to 32 bits by left shifting (padding with low instead of high zero).

    Also, the binary field in the big vs. little endian aren't the reverse of each other. To flip from big to little endian, you reverse the order of the bytes within the integer, keeping each byte value the same. (like x86 bswap). Their 11111111 (FF) byte is 2nd in their big-endian version, but last in little-endian.

    TL:DR: unfortunately, nothing about those images makes any sense that I can see.