且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么所有数据类型都是 2 的幂?

更新时间:2023-02-09 20:32:06

这是一个实现细节,并非总是如此.一些奇特的架构具有非二次幂的数据类型.例如,36 位字在某一阶段很常见.

That's an implementation detail, and it isn't always the case. Some exotic architectures have non-power-of-two data types. For example, 36-bit words were common at one stage.

2 的幂现在几乎普遍的原因是它通常简化了内部硬件实现.作为一个假设的例子(我不做硬件,所以我不得不承认这主要是猜测),指示其参数有多大的操作码部分可能被存储为参数中的字节数,因此两位足以表示参数是 8、16、32 或 64 位中的哪一个,并且将其转换为适当的锁存信号所需的电路将非常简单.

The reason powers of two are almost universal these days is that it typically simplifies internal hardware implementations. As a hypothetical example (I don't do hardware, so I have to confess that this is mostly guesswork), the portion of an opcode that indicates how large one of its arguments is might be stored as the power-of-two index of the number of bytes in the argument, thus two bits is sufficient to express which of 8, 16, 32 or 64 bits the argument is, and the circuitry required to convert that into the appropriate latching signals would be quite simple.