So on x86-64 it's big endian?
No, Intel CPUs are little endian: http://en.wikipedia.org/wiki/Endianness
First, you need to know that the smallest data unit that nearly all modern CPUs can manipulate is a byte, which is 8 bits. For numbers, we (human beings) write and read from left to right and we write the most significant digit first, so the most significant digit is on the left.
Little-endian byte order implies two things for the CPU:
Suppose that the CPU fetches 4 bytes from the memory, e.g. starting at address
0x00
, and that:- address
0x00
holds the byte11111111
, which is0xFF
; - address
0x01
holds the byte00111100
, which is0x3C
; - address
0x02
holds the byte00011000
, which is0x18
; - address
0x03
holds the byte00000000
, which is0x00
.
Then, when the CPU interprets these 4 bytes as an integer, it will interpret them as the integer value
0x00183CFF
. That is, the CPU will consider the byte at the highest address as the Most Significant Byte (MSB). That means, for the CPU, the higher the address is, the more significant the byte on that address is.- address
memory address: 0x00 0x01 0x02 0x03
binary value at address: 11111111 00111100 00011000 00000000
equivalent value in hex: = 0xFF = 0x3C = 0x18 = 0x00
- The same thing applies when the CPU writes an integer value like
0x00183CFF
to the memory. It will put0xFF
at the lowest address, and0x00
at the highest address. If you (human being) read bytes intuitively from low addresses to high addresses, you read outFF 3C 18 00
, which byte-for-byte is in the reverse order to how0x00183CFF
is written.
For BIG-endianness, the CPU reads and writes MSBs at lower addresses and LSBs at higher addresses.