Wednesday, April 30, 2008

Convert numbers between 0 and 1 to Binary

Take the decimal expression and repeat-
edly multiply it by 2. At each step, keep track of the integer part of the
result but do not carry it along in subsequent multiplications.

For example, convert decimal 0.7 to binary:
0.7 * 2 = 1.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2 etc.

The binary representation of decimal 0.7 is 0.1011001100...
where the "1100" repeats forever.

No comments: