0
$\begingroup$

For a programming exercise, I'm converting fractional numbers to their decimal representation. My test numbers happen to be "binary fractions" in the form:

$$\frac{1}{2^n}$$

For example:

$$ \frac{1}{2^{15}} = 0.000030517578125 $$

What baffles me is that the number of digits in the fractional part seems to be just $n$. In the example above, "000030517578125" has 15 digits.

I've tried this for $0 \leq n \leq 1000$ and the number of fractional digits always matched $n$.

Could someone explain this correlation to me?

$\endgroup$
2
  • 2
    $\begingroup$ Hint: $\frac{1}{2^n} = \frac{5^n}{10^n}$. $\endgroup$
    – dxiv
    Nov 25, 2016 at 18:15
  • $\begingroup$ @dxiv thanks, that really helped me to understand it. For positive $n$, $5^n$ is always smaller than $10^n$ and therefore doesn't affect to the number of fractional digits. $\endgroup$
    – Stefan
    Nov 26, 2016 at 8:44

1 Answer 1

1
$\begingroup$

It is easy to see that every time you multiply $\frac{1}{2} \cdot \frac{1}{2} \dots \frac{1}{2}$ in each multiplication you gain a significant decimal digit.

As an example just start multiply from the beginning:

$\frac{1}{2} = 0.5$ (1 digit)

$\frac{1}{2}\cdot\frac{1}{2} = 0.25$ (2 digits)

$0.25\cdot\frac{1}{2} = 0.125$ (3 digits)

$0.125\cdot\frac{1}{2} = 0.0625$ (4 digits)

Until you hit $\frac{1}{2^{n}}$ which has $n$ decimal digits

It is easy to see that every time you multiply $\frac{1}{2} \cdot \frac{1}{2} \dots \frac{1}{2}$ in each multiplication you gain a significant decimal digit.

As an example just start multiply from the beginning:

$\frac{1}{2} = 0.5$ (1 digit)

$\frac{1}{2}\cdot\frac{1}{2} = 0.25$ (2 digits)

$0.25\cdot\frac{1}{2} = 0.125$ (3 digits)

$0.125\cdot\frac{1}{2} = 0.0625$ (4 digits)

Until you hit $\frac{1}{2^{n}}$ which has $n$ decimal digits

EDIT:

Take the decimal part of $\frac{1}{2} = 0.5$. Then divide $\frac{5}{2}=2.5$ divide it by $10$ and you get $0.25$ which is $\frac{1}{2^{2}}$.

Now take the decimal part of the previous value $0.25$. Divide it by 2 = $\frac{25}{2} = 12.5$ divide it by 100 and you get $\frac{1}{2^{3}} = 0.125$

Take the decimal part of the previous $0.125$. Divide by 2 = $\frac{125}{2}=62.5$ and divide it by 1000, you end up with $\frac{1}{2^{4}} = 0.0625$

$\endgroup$
2
  • $\begingroup$ Well, I see that I gain a digit each time, but I don't really understand why it is exactly one more digit. It seems to be quite obvious, but I don't yet get it. $\endgroup$
    – Stefan
    Nov 25, 2016 at 18:38
  • $\begingroup$ I have edited my question with an example that tries to explain why you gain a digit in each step. Just take the decimal part as an integer part, divide it by $2$ and finally, divide it by $10^{n}$ where $n$ is the step(round) where you are at. $\endgroup$
    – kub0x
    Nov 25, 2016 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .