Search code examples
numbersbytecomputation-theory

Computational arithmetic - how many bits exactly for 8 digit number needed


how many bytes (and how many bits) you need to represent number 99999999 ? I need to know this: we have a calculator, the simplest possible, and can accommodate up to 8 digits, i.e. from 0 to 99999999 (let's forget the negatives, unless if you feel comfortable to include in your answer).

How many bits/bytes do we need to store values from 0 up to and inclusive 99999999 ?

I appreciate your help, kindly provide the theoretical background and any calculations if you can. Thank you very much!


Solution

  • Short answer is 27 bit, or 4 bytes which cover 32 bits. Longer answer is: you have to represent 10^8 values, so log2(10^8) roughly 26.575424759. Ceil this value, and you see 27. Ceil 27 with groups of 8 bits, and you have 32 bits, 4 bytes