Little-endian and Big-endian

前端 未结 4 960
你的背包
你的背包 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 18:11

    A good way to remember "which is which":

    Big-endian starts from the big (most-significant) end; little endian starts from the little end.

    For example, when regarding the word 0xA15D23B1 as a sequence of bytes, a big-endian machine starts it from the most significant byte 0xA1. It will be stored at the lowest address (this is the meaning of the potentially confusing word "start").

    By the way, if you only want to convert from big-endian to little-endian or back, you don't have to understand this: just reverse the order of bytes! This is why many people don't bother to understand what "big-endian" or "little-endian" means - you generally only need to understand whether or not to swap bytes.

提交回复
热议问题