Thursday, November 19, 2009

Fractional Number Conversion

To convert a fraction into binary, we can repeatedly multiply by 2, keeping the integer part.

After each multiplication, the integer part becomes the next binary digit (left to right), and
the fractional part gets multiplied by 2 again. We can continue until the fractional part is
zero, or until we have as many digits as we desire. For example, to convert 0.59375 (base 10)
into binary we multiply: .1 0 0 1 1 / / / / / .59375 * 2 = 1.1875 keep the 1 -----------+ / / / / \__/ / / / / /------------/ / / / / v / / / / .1875 * 2 = 0.375 keep the 0 ---------+ / / / \_/ / / / /-----------/ / / / v / / / .375 * 2 = 0.75 keep the 0 -------+ / / \/ / / /-----------/ / / v / / .75 * 2 = 1.5 keep the 1 -----+ / \/ / /------------/ / v / .5 * 2 = 1.0 keep the 1 ---+ Since the fractional part of the last multiplication is 0, we can stop and we have an exact
answer. (Any additional digits would simply be 0.) So our answer is 0.59375 (base 10) = 0.010011
(base 2). We can check this by converting the binary back to decimal. The fractional place values in
binary are: 1 1 1 1 1 . --- --- --- --- --- ... 2^1 2^2 2^3 2^4 2^5 or: 1 1 1 1 1 . - - - -- -- ... 2 4 8 16 32 or: . (.5) (.25) (.125) (.0625) (.03125) ... So 0.10011 (base 2) is: 1 * .5 = .5 + 0 * .25 = .0 + 0 * .125 = .0 + 1 * .0625 = .0625 + 1 * .03125 = .03125 -------- .59375 (base 10) So it double-checks. Notice that most fractions that terminate in a decimal will be
repeating fractions in binary. For example, let's convert the fraction 0.6 (base 10) to binary: .1 0 0 1 1 0 0 1 ... / / / / / / / / .6 * 2 = 1.2 keep the 1 ---+ / / / / / / / .2 * 2 = 0.4 keep the 0 ----+ / / / / / / .4 * 2 = 0.8 keep the 0 -----+ / / / / / .8 * 2 = 1.6 keep the 1 ------+ / / / / .6 * 2 = 1.2 keep the 1 -------+ / / / .2 * 2 = 0.4 keep the 0 --------+ / / .4 * 2 = 0.8 keep the 0 ---------+ / .8 * 2 = 1.6 keep the 1 ----------+ Notice that the second four lines repeat the first four, and the next four would repeat them,
and so on. Thus, our answer is: 0.6 (base 10) = 0.10011001... (base 2)

No comments:

Post a Comment