为什么所有数据类型都是 2 的幂? [英] Why are all datatypes a power of 2?

查看:51
本文介绍了为什么所有数据类型都是 2 的幂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么所有数据类型的大小总是 2 的幂?

Why are all data type sizes always a power of 2?

举两个例子:

short int 16
char 8

为什么他们不像下面这样?

Why are they not the like following?

short int 12

推荐答案

这是一个实现细节,并非总是如此.一些奇特的架构具有非二次幂的数据类型.例如,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.

这篇关于为什么所有数据类型都是 2 的幂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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