Here's how to think about the method.
Each time you multiply by 2, you change the binary representation of the number left by 1 place. You have moved the highest digit after the point to 1st place, so remove this number, and this is the first (highest, therefore the most left) digit of your fraction. Do it again and you will have the next digit.
Converting the base of an integer by dividing and taking the remainder, since the next digit shifts the number to the right. That's why you get the numbers in the reverse order, first the lowest.
This, obviously, can be generalized to any base, and not just 2, as indicated by GoofyBall .
One more thing to think about: if you round to N digits, stop at N + 1 digits. If the digit # N + 1 is one, you need to round (since binary numbers can only be 0 or 1, trimming the next digit, and 1 is just as inaccurate as truncating 5 to decimal).
PhilipM Apr 28 '15 at 11:38 2015-04-28 11:38
source share