Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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):

  • On a 32-bit little-endian processor, it will appear in memory as 67 45 23 01 EF CD AB 89.
  • On a 64-bit little-endian processor, it will appear in memory as EF CD AB 89 67 45 23 01.
  • On a 32-bit big-endian processor, it will appear in memory as 01 23 45 67 89 AB CD EF.
  • On a 64-bit big-endian processor, it will appear in memory as 01 23 45 67 89 AB CD EF.
like image 696
barak manos Avatar asked Jan 31 '14 11:01

barak manos


People also ask

Is x64 big-endian or little endian?

The IA-32 and x86-64 instruction set architectures use the little-endian format.

What is the endian format?

Endianness is a term that describes the order in which a sequence of bytes is stored in computer memory. Endianness can be either big or small, with the adjectives referring to which value is stored first.

Does endianness affect bit order?

Bit order usually follows the same endianness as the byte order for a given computer system. That is, in a big endian system the most significant bit is stored at the lowest bit address; in a little endian system, the least significant bit is stored at the lowest bit address.

Is Windows 10 big or little endian?

The following platforms are considered little endian: AXP/VMS, Digital UNIX, Intel ABI, OS/2, VAX/VMS, and Windows. On big endian platforms, the value 1 is stored in binary and is represented here in hexadecimal notation.


2 Answers

The first one is wrong. On ia32 at least the layout is EF CD AB 89 67 45 23 01.

The others are correct.

like image 79
Sergey L. Avatar answered Oct 17 '22 22:10

Sergey L.


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.

like image 41
Will Avatar answered Oct 17 '22 22:10

Will