When converting a fractional decimal value to binary, we need to use a slightly different approach. Instead of dividing by 2, we repeatedly multiply the decimal fraction by 2. If the result is greater than or equal to 1, we add a 1 to our answer. If the result is less than 1, we add a 0 to our answer.
The animation below demonstrates how to convert a decimal fraction to binary using repeated multiplication. Click on the "Start Tutorial" button to view the animation.
|
1011.0 + 0.011 1011.011 |
It is important to note that many decimal fractions do not have an exact representation in binary. For example, when we convert the decimal fraction 0.110 to binary, our answer looks like this:
0.00011001100110011001100...
Notice how this binary fraction repeats infinitely. Since we cannot represent some fractions exactly in binary, we cannot perform exact arithmetic with fractions. You may not realize it, but your computer actually has very tiny amounts of error in its computations. You rarely see these errors because the binary approximations are very close to the exact decimal value. However, when programmers write programs which perform many mathematical computations, they must consider this error to ensure their answers are reliable.