Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

converting decimal fraction to binary

Status
Not open for further replies.

PG1995

Active Member
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):
https://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.

Please help me.

Regards
PG
 

Attachments

  • imgus.jpg
    imgus.jpg
    96 KB · Views: 630
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.

PS: Made correction after seeing CZ's posting below. Thanks for pointing this out.
 

Attachments

  • fract.jpg
    fract.jpg
    352.5 KB · Views: 570
  • IMG.jpg
    IMG.jpg
    122.9 KB · Views: 697
Last edited:
If I wanted to convert a decimal fraction D into a binary fraction B, having N bits to the right of the decimal point, I'd simply multiply D x 2^N. This is the same as the multiply-by-2 method, just done in 1 step (and for a fixed bit size).

So, for 8 bits to the right of the decimal point, 0.625 x 2^8 = 160 = 0b10100000 (or binary 0.10100000 = 0.101). When converting 0.62, it might be the case, as you have found, that it either has a very long or never ending fractional sequence.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top