0

I have the following binary fraction: $$ 0.010011001100110011001100110011001100110011001100110100 $$ I want to know what number this represents in decimal. I could go like this: $$ \frac{1}{2}\cdot0 + \frac{1}{4}\cdot1 + \frac{1}{8}\cdot0 + ...$$ but this doesn't sound like the good approach. What's the algorithm? I searched the web and the algorithm is only presented for binary integers.

  • Why is the approach any worse than the equivalent one for integers? Adding up the product of bits and powers of two works for both. – Ian Miller Jul 21 '16 at 12:37
  • There exists a better approach for integers, I mentioned it here – Max Koretskyi Jul 21 '16 at 12:41
  • Second query - was your original binary fraction recurring. It looks like at the end you have potentially rounded it off. – Ian Miller Jul 21 '16 at 12:42
  • Yes, it was rounded – Max Koretskyi Jul 21 '16 at 12:44
  • The approach in your link still uses the same number of basic calculations (multiplications and additions). Can you quantify what you mean by 'better'? – Ian Miller Jul 21 '16 at 12:44
  • So your fraction was $0.01\overline{0011}$? – Ian Miller Jul 21 '16 at 12:45
  • @IanMiller, I can't see that, can you please rewrite the approach that answer to be looking like the one in this question so that I can see clearly that they are similar? – Max Koretskyi Jul 21 '16 at 12:46
  • @IanMiller, correct – Max Koretskyi Jul 21 '16 at 12:49
  • In your link you do 4 multiple and 4 add:

    $\begin{aligned} & 2\cdot0+1=1\ & 2\cdot1+1=3\ & 2\cdot3+0=6\ & 2\cdot6+0=12\ \end{aligned}$

    The alternate way to calculate $1100_2$ would be $8\cdot1+4\cdot1+2\cdot0+1\cdot0$

    Hmm I guess that approach requires calculating the powers which is therefore worse.

    – Ian Miller Jul 21 '16 at 12:49
  • @IanMiller, yes, you're right, it requires calculating powers. The alternative approach is better, but I can't seem to find the analogues one for a binary fraction – Max Koretskyi Jul 21 '16 at 12:51

2 Answers2

1

In base $10$, $0.392 = \dfrac{392}{10^3}$. Similarly, if you work in base $2$, $0.01011_2 = \dfrac{01011_2}{2^5} = \dfrac{11}{32}$ (if you want your final answer expressed as a fraction using integers in base $10$), if you have a good algorithm for converting integers from base $2$ to base $10$.

ADDED after OP clarified he meant a mixed periodic fraction:

Just like in base $10$, $0.03(045)_{10} = \dfrac{03045_{10} - 03_{10}}{99900_{10}}$, in base $2$ $0.01(0011)_2 = \dfrac{010011_2 - 01_2}{111100_2}$. The proof is the same as in base $10$, it uses the sum of a geometric series. I use parentheses to show the repeating part of the periodic fraction, instead of overline (that was the notation where I grew up, and it's easier to write).

  • only if one removes last 4 digits 0100 then fraction is recurring: 0.01(0011). Now it is not. One can use calculator 0.3000000000000000444089209850062616169452667236328125 – Adam Nov 01 '22 at 17:58
  • https://www.knowledgedoor.com/2/calculators/convert_a_number_with_a_non-repeating_fractional_part.html – Adam Nov 01 '22 at 17:58
1

You can reverse your process for binary integers. I'm using a smaller number as an example: $0.101011_2$ Start from the least significant bit and work towards.

$(0+1)\div2=0.5$

$(0.5+1)\div2=0.75$

$(0.75+0)\div2=0.375$

$(0.375+1)\div2=0.6875$

$(0.6875+0)\div2=0.34375$

$(0.34375+1)\div2=0.671875$

EDIT: How it works: $$0.671875=\frac{43}{64}=\frac{1}{64}+\frac{1}{32}+\frac{0}{16}+\frac{1}{8}+\frac{0}{4}+\frac{1}{2}$$ $$=(((((1/2 + 1)/2 + 0)/2 + 1)/2 + 0)/2 + 1)/2$$

An aside: As your fraction is recurring you can speed up the calculation using GP techniques but I don't think that was really what you were after.

Ian Miller
  • 11,844
  • thanks a lot, can you please also explain why this algorithm works? For example, the algorithm for integers works because the number $12$ can be represented in this form $12=2⋅(2⋅(2⋅(2⋅0+1)+1)+0)+0$ and from here I can clearly see why algorithm works. – Max Koretskyi Jul 21 '16 at 13:14