Technical Article => Programming => C

Converting Decimal Fractions to Binary

### Converting Decimal Fractions to Binary

In the text proper, we saw how to convert the decimal number 14.75 to a binary representation. In this instance, we \"eyeballed\" the fractional part of the binary expansion; 3/4 is obviously 1/2 + 1/4. While this worked for this particular example, we\'ll need a more systematic approach for less obvious cases.

In fact, there is a simple, step-by-step method for computing the binary expansion on the right-hand side of the point. We will illustrate the method by converting the decimal value .625 to a binary representation..

**Step 1**: Begin with the decimal fraction and multiply by 2. The whole number part of the result is the first binary digit to the right of the point.

Because .625 x 2 = 1.25, the first binary digit to the right of the point is a 1.

So far, we have .625 = .1??? . . . (base 2) .

**Step 2**: Next we disregard the whole number part of the previous result (the 1 in this case) and multiply by 2 once again. The whole number part of this new result is the *second* binary digit to the right of the point. We will continue this process until we get a zero as our decimal part or until we recognize an infinite repeating pattern.

Because .25 x 2 = 0.50, the second binary digit to the right of the point is a 0.

So far, we have .625 = .10?? . . . (base 2) .

**Step 3**: Disregarding the whole number part of the previous result (this result was .50 so there actually is no whole number part to disregard in this case), we multiply by 2 once again. The whole number part of the result is now the next binary digit to the right of the point.

Because .50 x 2 = 1.00, the third binary digit to the right of the point is a 1.

So now we have .625 = .101?? . . . (base 2) .

**Step 4**: In fact, we do not need a Step 4. We are finished in Step 3, because we had 0 as the fractional part of our result there.

Hence the representation of .625 = .101 (base 2) .

You should double-check our result by expanding the binary representation.

### Infinite Binary Fractions

The method we just explored can be used to demonstrate how some decimal fractions will produce infinite binary fraction expansions. We illustrate by using that method to see that the binary representation of the decimal fraction 1/10 is, in fact, infinite.

Recall our step-by-step process for performing this conversion.

**Step 1**: Begin with the decimal fraction and multiply by 2. The whole number part of the result is the first binary digit to the right of the point.

Because .1 x 2 = 0.2, the first binary digit to the right of the point is a 0.

So far, we have .1 (decimal) = .0??? . . . (base 2) .

**Step 2**: Next we disregard the whole number part of the previous result (0 in this case) and multiply by 2 once again. The whole number part of this new result is the *second* binary digit to the right of the point. We will continue this process until we get a zero as our decimal part or until we recognize an infinite repeating pattern.

Because .2 x 2 = 0.4, the second binary digit to the right of the point is also a 0.

So far, we have .1 (decimal) = .00?? . . . (base 2) .

**Step 3**: Disregarding the whole number part of the previous result (again a 0), we multiply by 2 once again. The whole number part of the result is now the next binary digit to the right of the point.

Because .4 x 2 = 0.8, the third binary digit to the right of the point is also a 0.

So now we have .1 (decimal) = .000?? . . . (base 2) .

**Step 4**: We multiply by 2 once again, disregarding the whole number part of the previous result (again a 0 in this case).

Because .8 x 2 = 1.6, the fourth binary digit to the right of the point is a 1.

So now we have .1 (decimal) = .0001?? . . . (base 2) .

**Step 5**: We multiply by 2 once again, disregarding the whole number part of the previous result (a 1 in this case).

Because .6 x 2 = 1.2, the fifth binary digit to the right of the point is a 1.

So now we have .1 (decimal) = .00011?? . . . (base 2) .

**Step 6**: We multiply by 2 once again, disregarding the whole number part of the previous result. Let\'s make an important observation here. Notice that this next step to be performed (multiply 2. x 2) is exactly the same action we had in step 2. We are then bound to repeat steps 2-5, then return to Step 2 again indefinitely. In other words, we will never get a 0 as the decimal fraction part of our result. Instead we will just cycle through steps 2-5 forever. This means we will obtain the sequence of digits generated in steps 2-5, namely 0011, over and over. Hence, the final binary representation will be.

.1 (decimal) = .00011001100110011 . . . (base 2) .

The repeating pattern is more obvious if we highlight it in color as below:

.1 (decimal) = .00011001100110011 . . . (base 2) .

#### RELATED

#### 0 COMMENT

No comment for this article.