Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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^n bits a better choice, or is just about compatibility with existing systems? (It's obviously convenient that a 64-bit register can hold two 32-bit pointers, or that a 32-bit data unit can hold 4 bytes.)

like image 354
Joonas Pulakka Avatar asked Oct 22 '09 12:10

Joonas Pulakka


People also ask

Why are bits always in powers of 2?

Because two is the base of the binary numeral system, powers of two are common in computer science. Written in binary, a power of two always has the form 100...000 or 0.00... 001, just like a power of 10 in the decimal system.

Why is memory in base 2?

Base 2 prefixes make sense for memory capacity because memory chips have a power-of-two capacity. Base 2 prefixes makes sense for address space because n bits can identify 2^n different addresses.

Can 2 be stored in a single bit?

You can't store anything other than a 1 or a 0 in a bit, so you can store 2 different numbers in a bit (but not at the same time).


1 Answers

That's mostly a matter of tradition. It is not even always true. For example, floating-point units in processors (even contemporary ones) have 80-bits registers. And there's nothing that would force us to have 8-bit bytes instead of 13-bit bytes.

Sometimes this has mathematical reasoning. For example, if you decide to have an N bits byte and want to do integer multiplication you need exactly 2N bits to store the results. Then you also want to add/subtract/multiply those 2N-bits integers and now you need 2N-bits general-purpose registers for storing the addition/subtraction results and 4N-bits registers for storing the multiplication results.

like image 59
sharptooth Avatar answered Sep 18 '22 19:09

sharptooth