Algorithm to convert binary fraction to decimal fraction

640 Views Asked by At

There's an algorithm to convert binary integer into decimal integer that is based on the expanded form of a number: $$ 12 = 2\cdot(2\cdot(2\cdot(2\cdot 0 + 1)+1)+0)+0 $$

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

I'm wondering if there's any similar algorithm to convert binary fraction to decimal fraction? Maybe also based on the expanded form: $$x_{1}\cdot 2^{-1}+x_{2}\cdot 2^{-2}+x_{3}\cdot 2^{-3} = 0.625$$

1

There are 1 best solutions below

1
On

Yes, you can do that.

Note that this is not often how it's done in practice, because it depends on doing most of the arithmetic on base-ten representations, which is awkward and slow on most computer architectures.

Instead one might, for example, start by multiplying by an appropriate power of ten (corresponding to how many decimals after the point you want), then remove the fractional part and convert the integer part to base ten by a standard algorithm. Afterwards put the decimal point back in.