Big endian and Little endian representations

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 13:15:34

Have a look at these pictures:

This is the list of endiannesses for all architectures/instruction sets

In a big-endian configuration, the most significant byte of a doubleword (32-bits on x86) is stored in the smallest address, and the least significant byte is stored in the largest address.
In a little-endian configuration, the least significant byte is stored in the smallest address.

Let's take the big-endian example first:

If we lay out your variables in memory in a big-endian configuration we get:

; -> Address increases ->

X: 01
Y: 00 05
Z: 11

or, grouped together:

 01 00 05 11
MSB       LSB

When viewed as a 32-bit value that equals 0x01000511. Adding 0x01000511 and 0xAA000101 gives us 0xAB000612. If we view the individual bytes in memory again we get:

; -> Address increases ->
AB 00 06 12

So the result is:

X = 0xAB
Y = 6
Z = 0x12

In a little-endian configuration we would have:

; -> Address increases ->

X: 01
Y: 05 00
Z: 11

or, grouped together:

 01 05 00 11
LSB       MSB

Viewed as a 32-bit value that equals 0x11000501. Adding 0xAA000101 gives us 0xBB000602. And when we view the individual bytes we get:

02 06 00 BB

With the result:

X = 2
Y = 6
Z = 0xBB

(Note: all x86 processors, AFAIK, are little-endian)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!