为什么同时使用小端和大端? [英] Why are both little- and big-endian in use?

查看:247
本文介绍了为什么同时使用小端和大端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在经过大约40年的二进制计算机科学学习后,为什么今天的低端字节序和大端字节序仍在使用?是否有一种算法或存储格式可以更好地使用一种方法,而另一种方法则更糟糕?

Why are both little- and big-endian still in use today, after ~40 years of binary computer-science? Are there algorithms or storage formats that work better with one and much worse with the other? Wouldn't it be better if we all switched to one and stick with it?

推荐答案

在将两个数字相加时(在纸上或在机器中),则从最低有效数字开始,然后朝最高有效数字迈进。 (许多其他操作也一样)。

When adding two numbers (on paper or in a machine), you start with the least significant digits and work towards the most significant digits. (Same goes for many other operations).

在Intel 8088上,该寄存器具有16位寄存器但有8位数据总线,由于其低位字节序允许在第一个存储周期后开始操作。 (当然,对一个单词的内存提取应该有可能以降序而不是增加的顺序进行,但我怀疑这样做会使设计有些复杂。)

On the Intel 8088, which had 16-bit registers but an 8-bit data bus, being little-endian allowed such instructions to start operation after the first memory cycle. (Of course it should be possible for the memory fetches of a word to be done in decreasing order rather than increasing but I suspect this would have complicated the design a little.)

在大多数处理器上,总线宽度与寄存器宽度匹配,因此这不再具有优势。

On most processors the bus width matches the register width so this no longer confers an advantage.

另一方面,可以从大端数字开始进行比较。 MSB(尽管许多比较指令实际上都执行减法,但无论如何都需要以LSB开头)。符号位也很容易获得。

Big-endian numbers, on the other hand, can be compared starting with the MSB (although many compare instructions actually do a subtract which needs to start with the LSB anyway). The sign bit is also very easy to get.


是否有算法或存储
格式更适合使用其中一种和
与另一个相比差很多?

Are there algorithms or storage formats that work better with one and much worse with the other?

不。

我实际上认为litte-endian更自然和一致:一点意义就是
2 ^ (bit_pos + 8 * byte_pos)。而对于大尾数,位的重要性为
2 ^(bit_pos + 8 *(word_size-byte_pos-1))。

I actually think litte-endian is more natural and consistent: the significance of a bit is 2 ^ (bit_pos + 8 * byte_pos). Whereas with with big endian the significance of a bit is 2 ^ (bit_pos + 8 * (word_size - byte_pos - 1)).


如果我们都切换到一个并坚持下去会更好吗?

Wouldn't it be better if we all switched to one and stick with it?

由于x86的优势,我们绝对偏向小端。许多移动设备中的ARM芯片具有可配置的字节序,但通常设置为LE以与x86世界更加兼容。对我来说很好。

Due to the dominance of x86, we've definitely gravitated towards little-endian. The ARM chips in many mobile devices have configurable endianness but are often set to LE to be more compatible with the x86 world. Which is fine by me.

这篇关于为什么同时使用小端和大端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆