Reputation: 30136
Suppose I have unsigned long long x = 0x0123456789ABCDEF
.
Which of the following is correct? (I can verify only the first one):
67 45 23 01 EF CD AB 89
.EF CD AB 89 67 45 23 01
.01 23 45 67 89 AB CD EF
.01 23 45 67 89 AB CD EF
.Upvotes: 10
Views: 29393
Reputation: 75665
Little endian means the least-significant bits are in the first byte, and big endian means the least-significant bits are in the last byte:
0x0123456789ABCDEF big endian is 0x01, 0x23, 0x45 ...
0x0123456789ABCDEF little endian is 0xEF, 0xCD, 0xAB ...
The native word endianess and size of the processor is inconsequential; the appearance in memory is dictated by the endian.
Upvotes: 4
Reputation: 22552
The first one is wrong. On ia32 at least the layout is EF CD AB 89 67 45 23 01
.
The others are correct.
Upvotes: 12
Reputation: 399969
I'd say the 32-bit solution is very much up to the compiler. It can choose to represent this type that it lacks native support for in any way it pleases, as long as the size is the expected one.
The 64-bit ones I'd agree with as being correct.
Upvotes: 1