Note that powers of 2 can be written in binary as
and so on. Observe that
digits are required to represent the
-th power of 2 in binary.
Also observe that
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,
That is, both 2 and 3 require only two binary digits, so we don't care about the decimal part of
. We only need the integer part,
, then we add 1.
Now,
, and 999 falls between these consecutive powers of 2. That means
which means 999 requires
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
? Or do you pad this number with 0s to get 10 digits, i.e.
? In the latter case, the answer is obvious;
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.