barak manos
barak manos

Reputation: 30136

Endian representation of 64-bit values

Suppose I have unsigned long long x = 0x0123456789ABCDEF.

Which of the following is correct? (I can verify only the first one):

Upvotes: 10

Views: 29393

Answers (3)

Will
Will

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

Sergey L.
Sergey L.

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

unwind
unwind

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

Related Questions