We all know how to convert decimal integral numbers to binary (don't we?) by the simple method of dividing succesively by 2 and using the remainders but what happens when we are trying to convert a decimal number which has a fractional part?
First we can see that it is obvious that the integral part of a decimal number will always be represented by an integral binary (with no fractional part) while the fractional part of a decimal number will always be represented by a fractional part of a binary number (with no integral part). An integral number will be integral in any integral base and a fractional number will be fractional in any integral base. This means we can split a decimal number into its integral and fractional parts, convert them separately to binary and add them up again in binary. This means we can forget about the integral part and concentrate on converting the fractional part. Some decimal fractions may convert into binary exactly (like .5625) but others may not (like .5624) and we may get an infinite number of binary digits in the binary fraction.
One way of converting a decimal fraction to binary fraction is to first multiply it by a power of 2 so that it becomes an integral number, then convert to binary and then divide by the same power of 2 (which now just means displacing the binary point to the left).
- Convert .5625 to binary.
- Multiply .5625 * 2^4 = 9
- Convert 9 to binary = 1001
- Divide 1001 / 2^4 = .1001
- Convert .5625 to binary
- Multiply .5625 * 2^10 = 576
- Convert 576 to binary = 1001000000
- Divide 1001000000 / 2^10 = .1001000000
(Same thing, more precision)
- Convert .5624 to binary
- Multiply .5624 * 2^20 = 589719.1424
- Convert 589719 to binary = 10001111111110010111
- Divide 10001111111110010111 / 2^20 = .10001111111110010111 (The more precision you want, the higher the power...