How to convert binary fraction to decimal

1.5k Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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.

2
On

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