# How to convert binary fraction to decimal

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. Jul 21 '16 at 12:37
• There exists a better approach for integers, I mentioned it here 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. Jul 21 '16 at 12:42
• Yes, it was rounded 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'? Jul 21 '16 at 12:44

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).

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.

• 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. Jul 21 '16 at 13:14