0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ For the fractional part, multiply by 2: if the answer is $\geq 1$, that digit is a one, otherwise it’s a zero. If it’s $\geq 1$, subtract 1. Then repeat. $\endgroup$ – Joe Aug 27 at 15:01
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thank you so much, this helped me a lot! If I can also ask, how to reverse the process from Binary to Decimal. The numbers after the decimal point I mean, I.E(11000.100) the .100 in this example. Thanks again for your help truly! $\endgroup$ – random-xyz Aug 27 at 15:56
  • $\begingroup$ @random-xyz In the same way. Multiply by ten, look at the integer part, convert that to decimal. Remove the integer part, then multiply by ten again. Rinse and repeat. Multiplying by ten in binary isn't as easy as multiplying by two in decimal, but the core idea is the same. Or, you could do it directly: $0.1_2 = 0.5_{10}$, then $0.01_{2} = 0.25_{10}$, and so on. Just add up all that apply (in our case, $0.5 + 0.0625 + 0.03125 + \cdots = 0.6$). $\endgroup$ – Arthur Aug 27 at 16:01
  • $\begingroup$ (Word of warning: When multiplying by $10$, you may encounter the infamous $0.11111\ldots_2$. Remember that that's equal to $1$. And similarily, $101.11111\ldots_2 = 110_2$, and so on.) $\endgroup$ – Arthur Aug 27 at 16:04
  • $\begingroup$ Thanks again Arthur. I'm sorry, my stupidity is kicking in:( and can't get the reverse part. If possible can you please give me an example on how to reverse back to Decimal. I'm really sorry for the trouble. $\endgroup$ – random-xyz Aug 27 at 16:17
  • $\begingroup$ @random-xyz Take $0.1010\ldots_2$ as an example. Multiply by $10_{10}=1010_2$ to get $110.1010\ldots_2$. The integer part is $110_2=6_{10}$, so the first digit after the point is $6$. Lop that off to get $0.1010\ldots_2$. Rinse and repeat. $\endgroup$ – Arthur Aug 27 at 16:32
0
$\begingroup$

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$$

$\endgroup$
0
$\begingroup$

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}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.