How many digits does a number have? $\lfloor \log_{2} n \rfloor +1$

332 Views Asked by At

From here we have seen that there are exactly $\lfloor \log_{10} n \rfloor +1$ digits in a decimal number $n$.
There is also mentioned that $n$ has $\lfloor \log_{2} n \rfloor +1$. Is it true? If yes how can I prove it?

1

There are 1 best solutions below

0
On

If $x$ is an $n-$digit number in base B, then

\begin{array}{c} B^{n-1} \le x \lt B^n \\ n-1 \le \log_Bx < n \\ n-1 \le \left\lfloor \log_Bx \right \rfloor < n \\ n \le \left\lfloor \log_Bx \right \rfloor + 1 < n+1 \\ \end{array}

It follows that the number of digits in a base-$B$ number is $\left\lfloor \log_Bx \right \rfloor + 1$.