Saturday, September 1, 2012

Fractions, from decimal to binary

Say we have 0.625 and we want to convert it into binary. We can write 0.625 = 1*0.5+0*0.25+1*0.125, so in binary 0.625 becomes .101. But we can do this conversion from decimal fraction to binary fraction in a more systematic way:
0.625 * 2 = 1.25 (1.25 >= 1) so first digit after radix point is 1, remainder 1.25-1.0 = 0.25. Now 0.25 * 2 = 0.5 < 1, so 2nd digit is 0; now 0.5*2 = 1.0 >= 1, so 3rd digit after radix point is again 1 and as now remainder = 1-1 = 0, we are finished. Though the second method is more systematic, it is not very clear how it is equivalent to the first one. In the first one we comare 0.625 with 0.5 and as 0.625 > 0.5, there will be a 1 for 0.5's place after radix point and so on. Now, checking whether 0.625 is greater than or equal 0.5 is equivalent to checking if 2*0.625 is greater than or equal to 2*0.5 = 1.0; next, the remainder is 0.625-0.5 = 0.125, now comparing 0.125 and 0.25 is equivalent to comparing 2*(2*0.625-2*0.5) and 2*(2*0.25) or 2*0.25 and 1.0; and so on...

No comments:

Post a Comment