Regarding byte order: A layman’s explanation Host Order, Network Order, observed directly via debugger
In the field of computer science, certain design habits have formed due to historical reasons, just like the width of a hip dictates the width of a rocket’s thrusters – there’s no need to rigidly analyze their “advantages” and “disadvantages”; it’s simply a matter of historical convention.
Original Link
Author: Beiji (North Pole) Link: https://www.zhihu.com/question/637413724/answer/3346032134 Source: Zhihu Copyright belongs to the author. For commercial reprints, please contact the author for permission. Non-commercial reprints must indicate the source.
Text Translation
Here’s the translation of the provided text into English:
- Data Mining
- Deep Learning
- Neural Network
Nowadays, the current situation is a result of historical habits plus commercialization, and it has little to do with technology itself. ARM can be set up as big-endian or little-endian. The TCP/IP header still uses big-endian (network byte order). There are also many storage protocols/specifications that use big-endian to store data.
Therefore, the three questions posed by the user seem incorrect in today’s view:
- Why do computers generally adopt little-endian storage? –> Incorrect.
- Why is storing the low byte in a little-endian manner more efficient than in a big-endian manner? –> Efficiency will not be higher.
Any argument about these three questions using current technology is like shooting an arrow first and then drawing the target.
However, if we say that the choice of big-endian or little-endian did have some objective factors in the history of computer development: The advantage of host-byte order (little-endian) is that a 8-bit * 4 adder can be easily made, requiring only an 8-bit adder to sequentially add all bytes from low to high, and the carry circuit is very simple. If it were big-endian, it would require loading 32 bits once, which cannot perform calculations. Nowadays, the difference between loading 8 bits or 32 bits is not significant, but in the early days when storage prices were expensive, simplicity was always preferred, so the host-byte order chose little-endian based on cost considerations. The advantage of network byte order (big-endian) is that early devices had very small caches. Taking the high byte first could quickly determine the message information: packet length (need to prepare how much cache), address range (IP addresses are matched from front to back). Early network devices’ caches were at the byte level, and taking the high byte was indeed a little faster. Therefore, network devices used big-endian based on cost considerations.
So, the choice of byte order has historically been more influenced by application scenarios and costs (such as PPC/MIPS being more suitable for network devices), and the configuration of big-endness and little-endness has been carried over to this day due to compatibility reasons. In today’s view, these advantages no longer exist, they are merely historical habits.