Why is the smallest value that can be stored is a Byte(8bit) & not a Bit(1bit)?

老子叫甜甜 提交于 2019-12-12 12:31:02

问题


Why is the smallest value that can be stored a Byte(8bit) & not a Bit(1bit) in memory? Even booleans are stored as Bytes. Will we ever bump the smallest number to 32 or 64bits like register's on the CPU?


回答1:


The underlying methods of processor access are limited to the size of the smallest usable register. On most architectures, that size is 8 bits. You can use smaller portions of these; for instance, C has the bitfield feature in structs that will allow combining fields that only need to be certain bit lengths. Access will still require that the whole byte be read.

Some older exotic architectures actually did have different a "word size." In these machines, 10 bits might be the common size.

Lastly, processors are almost always backwards compatible. Intel, for instance, has maintained complete instruction compatibility from the 386 on up. If you take a program compiled for the 386, it will still run on an i7 processor. Changing the word size would break compatibility. So while it is possible, no manufacturer will ever do it.




回答2:


The hardware is built to read data in blocks (bytes, later words and dwords). This provides greater efficiency, than accessing individual bits, and also offers more addressing range. So most data is aligned to at least byte boundary. There exist encodings that operate with bit sequences, rather than bytes, but they are quite rare.

Nowadays the data is most often aligned to dword (32-bits) boundary anyway. Moreover, some hardware (ARM, for example), can't access misaligned multibyte variables, i.e. 16-bit word can't "cross" dword boundary - exception will be thrown.




回答3:


Because computers address memory at the byte level, so anything smaller than a byte is not addressable.



来源:https://stackoverflow.com/questions/4607572/why-is-the-smallest-value-that-can-be-stored-is-a-byte8bit-not-a-bit1bit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!