Little-endian and Big-endian

前端 未结 4 957
你的背包
你的背包 2021-01-27 17:43

I must write a routine for conversion between the 2 representations. But I\'m a bit confused. If I have an architecture with a memory with words of 32 bits and I must store the

4条回答
  •  星月不相逢
    2021-01-27 17:47

    Big-endian memory layout is most significant bytes first, whereas little-endian layout is least significant bytes first. Given the value 0xA15D23B1:

    Memory address    0  1  2  3
    Big-endian       A1 5D 23 B1
    Little-endian    B1 23 5D A1
    

    Note that big-endian memory layout does not change with respect to word size, but little-endian does. If you consider two short words (16 bit), 0xA15D and 0x23B1 stored contiguously:

    Memory address    0  1  2  3
    Big-endian       A1 5D 23 B1
    Little-endian    5D A1 B1 23
    

提交回复
热议问题