How to convert decimal with fraction to a binary

2.1k Views Asked by At

Can anyone help me please. I want to know how to convert a decimal number that has fraction to binary number. For example 1,7 or 24.6 etc... I know how to convert a whole number to binary but I'm struggling with this. Thanks in advanced for any help.

3

There are 3 best solutions below

5
On BEST ANSWER

Let's take $24.6$ as an example. Presumably, you know how to convert $24_{10}$ into $11000_2$, so I won't bother to explain that in any detail.

That means we're left with $0.6_{10}$ unaccounted for. Here is the standard algorithm for converting that to binary:

Multiply by $2$. We get $1.2_{10}$. This is larger than or equal to $1$, so the next bit after the point is $1$. Thus so far we have $11000.1_2$. We've taken care of the $1$ in $1.2_{10}$, so we remove that and are left with $0.2_{10}$.

Multiply by $2$. We get $0.4_{10}$. This is less than $1$, so the next bit in our number is $0$. Thus so far we have $11000.10_2$.

Multiply by $2$. We get $0.8_{10}$. This is less than $1$, so the next bit in our number is $0$. Thus so far we have $11000.100_2$.

Multiply by $2$. We get $1.6_{10}$. This is greater than or equal to $1$, so the next bit in our number is $1$. Thus so far we have $11000.1001_2$. We have now taken care of the $1$ in $1.6_{10}$, so we remove that and are left with $0.6_{10}$.

And so on.

As for why this works, this is basically a different way of saying "repeatedly multiply by $2$, then check whether the one's bit of the result is $0$ or $1$". (In other words, if you lop off everything after the point, is the result even or odd?) This is what we want to look for because multiplying by $2$ will cause the binary point to just move one spot to the right. So for each time we multiply by $2$, we are studying the next bit and only the next bit. The subtracting of $1$ is there only to make the calculations more bearable, especially if we want to keep doing it for a while, or we want to be certain that we've hit a repetition.

0
On

Having converted the whole part, you can think of the process as finding which of $\frac 12, \frac 14, \frac 18, \frac 1{16},\ldots$ you need to add together to get the fractional part. If the denominator is not a power of $2$ the expansion will repeat. Keep doubling the fraction and keep track of the carries into the $1$s place. For your example of $\frac 35=0.6$ you would do $$0.6 \cdot 2=1.2=0.2+1\\ 0.2 \cdot 2 = 0.4=0.4+0\\ 0.4 \cdot 2 = 0.8=0.8+0\\ 0.8 \cdot 2=1.6=0.6+1$$ And we are back where we started, so this is the repeat. We have $$0.6_{10}=0.\overline{1001}_2$$

0
On

If you have some number $a$ with $n$ digits repeated in binary, then you have $a2^{-n}+a2^{-2n}+...$ (each time you repat the number, you're multiplying it by another factor of $2^{-n}$. This is a geometric series, so it adds up to $\frac {a2^{-n}}{1-2^{-n}}=\frac a {2^m-1}$. The decimal $.6$ is equal to $\frac 3 5$, so we're looking for $n$ such that $2^n$ is divisible by $5$, which leads to $n=4$, $2^n=16$, $2^n-1=15$. Then $a=9$, and $9$ in binary is $1001$. Thus, $.6_{10}=.\overline{1001}_2$

This works for other fractions. For instance, $\frac 1 {11}=\frac{93}{1023}=\frac{93}{10^{10}-1}$, $\frac{1}{11} = .\overline{0001011101}_2$.

This also applies to base ten: $\frac 1 {11} = \frac 9 {99}= \frac 9 {10^2-1}$, so $\frac 1 {11} = .\overline{09}$