[Math] leading digits of large power of 2

elementary-number-theory

How do I get the leading digits for a large power of 2 (say $2^{123456789}$, although I want a general method)? I was thinking about repeatedly dividing it by ten, but I don't know how to do that efficiently without calculating the number itself, and I was also thinking $\log(a) < 123456789\log(2) < b$ would imply that it would be the first three digits of $a$, but I don't know how I would find $a$ and $b$ in the first place.

Best Answer

Figured it out! We first need to find the number of digits of $2^n$, which can be done using logarithms: we need to solve (approximately) $2^n = 10^d$. In the end, the formula for the number of digits $d$ is $d = 1+\left\lfloor n\,\log_{10}2\right\rfloor$. Then, once we have $d$, then we see that if we can solve for $10^{d-k} \cdot t < 2^n < 10^{d-k} \cdot (t + 1)$ (where $k$ is the number of leading digits we want), then $t$ is the number we want. In this specific example, we find that the first three digits are $\lfloor 10 ^ {n \log2 - d + 3}\rfloor = 454$, where $n = 123456789$ and $d$ is calculated as above.