converting decimal fraction to binary

PG1995

Joined Apr 15, 2011
816
Hi

I'm learning to convert decimal fractions into their binary equivalent.

1: After the decimal point 2's powers are in negative: 2^-1, 2^-2, 2^-3, ...; and this is equivalent to: 0.5, 0.25, 0.125, ....

Let's say we want to convert 0.625 into its a binary fraction.

If we subtract "0.5" or "2^-1" from 0.625 we are left with 0.125 and "0.125" can be represented by 2^-3.

Therefore,
0.625 = 0.5 + 0 + 0.125 = 0.101

The above example was found in a book. Suppose, we have 0.620 instead. How would we convert it into a binary fraction using the method we used above? How do I use this method so that I can deal with any given decimal number?

2: I know there is another method of repeated multiplication by 2. Though this method seems simple but it's not that much natural. Please have a look on the linked scan (or, you can check the attachment):
http://img809.imageshack.us/img809/4655/imgus.jpg

I have tried to apply repeated multiplication method to convert a decimal fraction to a binary one. In case of 0.3125 I was successful but then I tried to apply it on 0.620 without any success. It seems the method would never end.

Regards
PG

Attachments

• 216.3 KB Views: 85

Papabravo

Joined Feb 24, 2006
13,697
0.620 may not have an exact binary representation. You can however get arbitrarily close to 0.620 it is just a question of how many places you want to work with and weather you choose to be above 0.620 or below 0.620

My conjecture is that if you take any decimal number and write it as a fraction, then factor the numerator and denominator into prime factors, then cancel the common factors. You must end up with only twos in the denominator to have an exact representation.
Rich (BB code):
0.620 = 620 / 1000 = (2*2*5*31) / (2*2*2*5*5*5) = 31 / (2*5*5) = 31 / 50
since there is a pair of 5's left in the denominator 0.620 does not have an exact representation and any algorithm you employ witll fail to terminate as you have already observed.

Last edited:

PG1995

Joined Apr 15, 2011
816
It seems now I understand how the method of repeated multiplication by 2 really works. Please check the attachment.

To someone like me who stumbles onto this thread:
The bases which have direct relationship with 2 such as 8, 16, 32, etc. can easily be converted between each other. For example, an octal number such as (562) can easily be converted into a binary one.

562 = 5 6 2 = (101) (110) (010) = 101110010

To see how this works please check the attachment.

Attachments

• 146.5 KB Views: 73
• 122.9 KB Views: 72
Last edited:

Papabravo

Joined Feb 24, 2006
13,697
Yup. Nothing has changed much since the introduction of "The New Math" more than 50 years ago.