the gk tlks Finding answers for the curious mind
Binary to Decimal - Dealing with fractions
Binary to Decimal - Dealing with fractions

We generally have no problem dealing with converting binary to decimal i.e base 2 to base 10 representation.

So if I say how would I convert 52 which is a base 10 or decimal representation of the number to binary.
It would be basically saying converting 5*10+ 2*10to binary.

I don't know why did i write a decimal representation here, yeah but let's carry on. Let's assume i do not have a backspace / delete button   

So (52)10 binary conversion would be,

Number (to be divided by 2) QuotientRemainder
52/2260
26/2130
13/261
6/230
3/211
1/201


So checking the remainder(the top being the bit with the lowest order) we would get 110100

And how to convert the binary to decimal, we can do

0*20 + 0*21 + 1*22 + 0*23 + 1*24 + 1*25 which equals 0+0+4+0+16+32 which becomes 52. We got our math right then.

Now, what about fractions how would we deal with it??

So let's say we take number 52.25 which we need to convert to binary.

How do we approach this??

First let's separate the integer and the fractional part, so we would have 52 and 0.25. Let's do the binary conversion for both separately as well.

For (52)10 we have already done the binary conversion which would be 110100. Now for 0.25 how should we go about it. Instead of dividing we would be multiplying by 2 until we get a fractional part as 0

Number(Multiply by 2)ResultFractional PartInteger 
0.25*20.50.50
0.5*2101

 

Now calculating the integer would make the (0.25)10 binary conversion as 0.01

So 52.25 to binary representation would be (110100.01)2

Now if you want convert the binary fraction to decimal, we continue like we did for the integer part. 

For example for .01 we would be doing 0*2-1 + 1*2-2 which is basically saying

0*(1/21) + 1*(1/22)

0*0.5 + 1*0.25 

0.25 which is the number in decimal format. 

This may seem to be end of it.. Believe me it's not. 

So the number 0.25 seems to come in power of 2 of in the finite domain of the power of 2. What if there is a number which does not come in power of 2?? say 0.13

Like in the decimal numbering system we have representation for 1/2 which is 0.5 however when we take 1/3 we go 0.33333333 recurring right??

Similarly if we want to take 0.13 or even 0.1 to be converted to binary, let's see how it goes..

Number(multiply by 2)ResultFraction Integer
0.1*20.20.20
0.2*20.40.40
0.4*20.80.80
0.8*21.60.61
0.6*21.20.21
0.2*20.40.80
0.4*20.80.80
0.8*21.60.61


Now we can see that the pattern is going to be recurring which would be kind of infinitesimally long so may be we can loosely say (0.1)10 can be translated to binary as 0.00011001 recurring.

Right??

Now if we convert this to decimal we might not arrive at 0.1 but somewhere around 0.097 or 0.096 or a similar fraction.

Given this case what if you ask a computer or do a fraction addition like 0.1+0.2 what do you think would be the answer??

Refer below links to get more information on that..

What the Binary!!

Who stole my money?? Double or Float

And until next time... Remember the curiosity talks!!

Powered by Froala Editor