I am having trouble to get the intuition behind the following approach: We take the fraction point (say: .642) and continuously multiply by 2, taking whatever ends up right of the point as our next number (either 0 or 1) after the fixed point in the binary number. Then we take whatever is left after the decimal point and repeat.
1 Answers
I believe there is a typo in your post; we take the integer 0 or 1 to the left of the decimal point.
The base-10 decimal $.a_1a_2a_3 ... a_n + ...$ of course represents $a_1 * 10^{-1} + a_2 * 10^{-2} + ... + a_n * 10^-n + ...$ where all the $a_i$ are digits 0 to 9.
We want to change this to the base-2 representation $.c_1c_2c_3 ... c_n + ...$ representing $c_1 * 2^{-1} + c_2 * 2^{-2} + ... + c_n * 2^-n + ...$ where all the $c_i$ are binary digits 0 or 1.
If we multiply (in base 10) $ 2 * (c_1 * 2^{-1} + c_2 * 2^{-2} + ... + c_n * 2^-n + ...) $ we obtain $ c_1 + c_2 * 2^{-1} + c_3 * 2^{-2} + ... + c_{n+1} * 2^{-n} + ...$
Thus the integer $c_1$ is separated from the rest of the fractional representation. If we then remove this $c_1$ from the decimal, another multiplication by 2 will separate the integer $c_2$, and so on, repeating either to the end or to the accuracy desired. We note that the integers 0 and 1 (only) are the same in binary and decimal.
So we take the example $x$ = .642 base 10
Multiply by 2, and we get 2 * .642 = 1.284
It is to be noted that when we "carry" a digit in base 10 multiplication, 2 times a digit from 1 to 9, the highest result is 18 so the "carry" to the units place will always be 0 or 1, as required for our binary $c_i$.
Back to the example, we take the 1 or 0 to the left of the decimal so the binary representation starts .1 and the remaining decimal is .284
Repeating
2 * .284 = .568
Zero in units
Binary representation .10...
2 * .568 = 1.136
1 in units
Binary representation is .101...
2 * .136 = .272
0 in units
Binary representation is .1010...
2 * .272 = .544 0 in units Binary representation is .10100...
2 * .544 = 1.088
1 in units
Binary representation is .101001...
This binary decimal is non-terminating but the calculation can be taken to any degree of accuracy required, or we can find the repeating pattern.
Check: The binary representation .101001... represents in decimal form $ 1 * 2^{-1} + 0 + 1 * 2^{-3} + 0 + 0 + 1 * 2^{-6}$ + further smaller terms = 1/2 + 1/8 + 1/64 + further smaller terms = .5 + .125 + .015625 + further smaller terms = .640625 + other smaller terms
We see we are approaching .642 base 10 as required.
- 1,429
-
Hi, thanks for the reply. However, exactly why multiplying with 2 (with base 10) and taking the carry works is still a little eery to me. – Kevin Wu Feb 04 '17 at 19:14