# Is there an algorithm to find the number of digits in 2^n, where n is a positive integer?

Is there an algorithm to find the number of digits in 2^2030 ?

$2^1=2$

$2^2=4$

$2^3=8$

$2^4=16$

$2^5=32$

$2^6=64$

$2^7=128$

...

$2^{10}=1024$

-

The number of digits in $2^n$ is $1+floor(n \log_{10} 2)$.

Using $\log_{10} 2 \approx 0.30103$ gives you 612 digits.

Here is an explanation:

A number $x$ has $k$ digits in base 10 iff $10^{k-1} \le x < 10^k$. Taking logs, we get $k-1 \le \log_{10} x < k$, which means that $floor(\log_{10} x)=k-1$. So, $k=1+floor(\log_{10} x)$.

An answer to the question in the title needs high-precision approximations of $\log_{10} 2$.

-
Care to explain why is this the case? –  JohnWO Jun 21 '13 at 12:52
@JohnWO, see my edited answer. –  lhf Jun 21 '13 at 13:00
See also oeis.org/A129344 and try to find a pattern. –  lhf Jun 21 '13 at 13:08
You can use \lfloor and \rfloor to get the $\lfloor$ and $\rfloor$ symbols. –  Peter Phipps Jun 21 '13 at 13:09
@PeterPhipps, I know. I was lazy and also not sure the OP would understand the notation. –  lhf Jun 21 '13 at 13:10

Just for fun, let's suppose you don't have access to floating-point computations, but you can compute with rational numbers. We have the series (for $|x|<1$) $$\ln \left( \frac{1+x}{1-x}\right) = 2 x + \frac{2}{3} x^3 + \frac{2}{5} x^5 + \frac{2}{7} x^7 + \ldots$$ and in particular, if $0 < x < 1$, $$2 x + \frac{2}{3} x^3 + \frac{2}{5} x^5 + \frac{2}{7} x^7 < \ln\left( \frac{1+x}{1-x}\right) < 2 x + \frac{2}{3} x^3 + \frac{2}{5} x^5 + \frac{2 x^7}{7(1 - x^2)}$$ For $x = 1/3$ this gives us $$\dfrac{53056}{76545} < \ln(2) < \dfrac{23581}{34020}$$ while for $x = 1/9$ we have $${\frac {37355104}{167403915}} < \ln \left( 5/4 \right) < {\frac { 3689393}{16533720}}$$ Then $2030 \log_{10}(2) = \dfrac{2030 \ln 2}{\ln(5/4) + 3 \ln(2)}$ is between $\dfrac{23263994880}{38070491}$ and $\dfrac{94221399069}{154182208}$, both of which are between $611$ and $612$. So, $612$ digits.

-