4

This seems like such a simple question but I can't seem to come up with an answer.

I know the formula for the number of digits of $2^n$ is $1+[nlog(2)]$.

So the amount of decimal digits of $2^{100}$ would be $1+[100log(2)] \approx 70$.

How would I be able to mathematically determine the amount of binary digits in this number, though? How many bits does $2^n$ have if written in base 2?

Jaken
  • 546
  • Decimal digits: Use $\log_{10}$. Binary digits, aka bits: use a logarithm with a different base. – pjs36 Sep 01 '15 at 04:07
  • @pjs36 $1+log_2 (2)$? – Jaken Sep 01 '15 at 04:17
  • 1
    The number of base-$b$ digits needed to represent $n$ is $1+\left\lfloor\log_b(n)\right\rfloor$. Then use $\log_2(2^n)=n$. – robjohn Sep 01 '15 at 09:14
  • How did you get "70"? 2^100 has ~30 digits. To approximate: 2^10=1,024 - so ~ every 10 binary digits has 3 decimal digits (1.024e3). So, 2^100 -> 100/10=10 -> 10*3=30. – iAmOren Dec 11 '22 at 10:38

2 Answers2

4

Since $$2^n = 1 \cdot 2^n + 0 \cdot 2^{n-1} + \ldots + 0 \cdot 2^1 + 0 \cdot 2^0$$ the number $2^n$ expressed in base $2$ is just $$\underbrace{10\cdots0}_{n+1 \text{ digits}}$$

In general, the number of digits in the base $b$ expansion of $n$ will just be the exponent of the smallest power of $b$ that is not less than $n$ (note that this is the same as computing $\lceil \log_{b}(n) \rceil$).

For example, if I wanted the number of digits in the base $3$ expansion of $2^{100}$, I would "simply" note that $3^{63} < 2^{100} < 3^{64}$, and so conclude that the base $3$ expansion of $2^{100}$ has $64$ digits. If you wanted to do this quickly, say with a calculator, you would just compute $\lceil \log_{3}(2^{100}) \rceil$ by computing $$\log_{3}(2^{100}) = \frac{\log_{10}(2^{100})}{\log_{10}(3)} \approx \frac{30.1029996}{0.4771212} \approx 63.0929754 $$ and then rounding up to the nearest integer.

Let's do a simple test to make sure. Since $141 = 1 \cdot 5^3 + 0 \cdot 5^2 + 3 \cdot 5^1 + 1 \cdot 5^0$, the number $141$ has $4$ digits when expressed in base $5$. Now $$\log_{5}(141) = \frac{\log_{10}(141)}{\log_{10}(5)} \approx \frac{2.1492191}{0.6989700} \approx 3.0748374$$ therefore $\lceil \log_{5}(141) \rceil = 4$, as desired.


The takeaway is that you can quickly get the number of digits in the base $b$ expansion of $n$ by plugging $$\frac{\log_{10}(n)}{\log_{10}(b)}$$ into your calculator and then rounding up to the nearest integer.

727
  • 1,607
  • 1
    See problem illustred by base2 at https://www.exploringbinary.com/number-of-bits-in-a-decimal-integer/ , "fails when n is a power of two". – Peter Krauss Feb 19 '19 at 02:48
4

$2^n$ written in base $2$ has exactly $n+1$ binary digits (bits). Just like $10^n$ written in base $10$ has $n+1$ decimal digits.

$2^{100}$ is

$$1\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000\,0000000000_b.$$

For any number $N$ written in any base $b$, the number of figures is

$$\lfloor log_b(N)\rfloor+1.$$

  • 2
    Supposing the correct answer. See same result at https://www.exploringbinary.com/number-of-bits-in-a-decimal-integer/ – Peter Krauss Feb 19 '19 at 02:49