189k views
0 votes
How many bits are required to represent the decimal numbers in the range from 0 to 999 in straight binary code?

1 Answer

3 votes
Note that powers of 2 can be written in binary as


2^0=1_2

2^1=10_2

2^2=100_2

and so on. Observe that
n+1 digits are required to represent the
n-th power of 2 in binary.

Also observe that


\log_2(2^n)=n\log_22=n

so we need only add 1 to the logarithm to find the number of binary digits needed to represent powers of 2. For any other number (non-power-of-2), we would need to round down the logarithm to the nearest integer, since for example,


2_(10)=10_2\iff\log_2(2^1)=\log_22=1

3_(10)=11_2\iff\log_23=1+(\text{some number between 0 and 1})

4_(10)=100_2\iff\log_24=2

That is, both 2 and 3 require only two binary digits, so we don't care about the decimal part of
\log_23. We only need the integer part,
\lfloor\log_23\rfloor, then we add 1.

Now,
2^9=512<1024=2^(10), and 999 falls between these consecutive powers of 2. That means


\log_2999=9+\text{(some number between 0 and 1})

which means 999 requires
\lfloor\log_2999\rfloor+1=9+1=10 binary digits.

Your question seems to ask how many binary digits in total you need to represent all of the numbers 0-999. That would depend on how you encode numbers that requires less than 10 digits, like 1. Do you simply write
1_2? Or do you pad this number with 0s to get 10 digits, i.e.
0000000001_2? In the latter case, the answer is obvious;
1000*10=10^4 total binary digits are needed.

In the latter case, there's a bit more work involved, but really it's just a matter of finding how many number lie between successive powers of 2. For instance, 0 and 1 both require one digit, 2 and 3 require two, while 4-7 require three, while 8-15 require four, and so on.
User Fknx
by
7.6k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories