An Explanation of Byte Order [Host Order, Network Order, Observing Directly Through a Debugger]
Some design habits formed due to historical reasons in the computer field are like the principle that the width of a horse’s rear end determines the width of a rocket engine – there’s no need to analyze their “advantages” and “disadvantages”; they’re simply historical conventions
Original link
Author: Arctic Link: [https://www.zhihu.com/question/637413724/answer/3346032134] Source: Zhihu Copyright belongs to the author. For commercial reproduction, please contact the author for authorization; for non-commercial reproduction, please indicate the source.
Reprint of the main text
The current endianness situation is a result of historical habits and commercialization, not really related to the technology itself. ARM can be configured as either big-endian or little-endian. The TCP/IP header still uses big-endian (network byte order). There are also many storage protocols/specifications in the storage field that save data in big-endian format.
So, the three questions raised by the original poster, looking back today:
- Why do computers generally use little-endian storage? –> Incorrect
- Efficiency is not necessarily higher
Any attempt to justify these three issues based on current technology is like drawing a target before shooting an arrow
However, when it comes to the choice between big-endian and little-endian, there were indeed certain objective factors in the history of computer development: Advantages of host byte order (little-endian): Little-endian adders are easier to implement. If you want to build an 8-bit * 4 adder, you only need one 8-bit adder and can simply loop through all bytes from low to high and add them. The carry circuit is very simple. However, with big-endian, you need to load 32 bits at once, otherwise the calculation cannot be performed. Looking at it now, there’s not much difference between loading 8 bits or 32 bits, but decades ago, memory was expensive, so simplicity was preferred. Therefore, the choice of little-endian for host byte order was based on cost considerations. Advantages of network byte order (big-endian): Early devices had very small caches, and receiving the high byte first allowed for quick determination of packet information: package length (how much cache to prepare), address range (IP addresses are matched from front to back). Early networking devices used bytes as their unit, so taking the high byte first was indeed faster. Therefore, network devices use big-endian, also based on cost considerations.
Therefore, the choice of byte order has historically been driven more by application scenarios and cost considerations (such as PPC/MIPS being better suited for network devices), and later, due to compatibility reasons, the endian configuration has continued to be used until today
Looking at it today, these advantages no longer exist at all; they are merely historical habits