To convert a decimal fraction to Base 2…

From a great online course in Assembly programming:

http://chortle.ccsu.edu/AssemblyTutorial/Chapter-29/ass29_13.html

Converting Representation from Decimal to Binary

  Decimal Binary so far
Start 0.625 0.
×2 1.250 0.1
  .250 0.1
×2 0.500 0.10
  .500 0.10
×2 1.000 0.101
Result .000 0.101

Often you need to convert a decimal expression like 7.625 into a binary expression. To do this, first convert the whole number (7 in this case) to binary (111 in this case), append a binary point, and convert the decimal fraction to binary.

To convert a decimal fraction to Base 2:
Repeatedly multiply the decimal fraction by two. After each multiplication, copy the bit (0 or 1) that moves into the one’s place
(the place just left of the radix point) to the right of the binary fraction, then erase it from the decimal fraction.
Stop when the decimal fraction is zero.

(Note: if this never happens, stop when you have enough bits in the binary fraction.)

For our example: 7.625 is 111.1012.
In this case the conversion stopped when the decimal
fraction changed to zero.
This may not always happen.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s