Why is number of bits always(?) a power of two?

后端 未结 18 2018
天涯浪人
天涯浪人 2021-01-30 10:17

We have 8-bit, 16-bit, 32-bit and 64-bit hardware architectures and operating systems. But not, say, 42-bit or 69-bit ones.

Why? Is it something fundamental that makes 2

18条回答
  •  误落风尘
    2021-01-30 10:48

    A common reason is that you can number your bits in binary. This comes in useful in quite a few situations. For instance, in bitshift or rotate operations. You can rotate a 16 bit value over 0 to 15 bits. An attempt to rotate over 16 bits is also trivial: that's equivalent to a rotation over 0 bits. And a rotation over 1027 bits is equal to a rotation over 3 bits. In general, a rotation of a register of width W over N bits equals a rotation over N modulo W, and the operation "modulo W" is trivial when W is a power of 2.

提交回复
热议问题