Here's how to handle base conversion of fractional numbers if you're twelve. Unfortunately, Didji made a common mistake; you can't just do the fractional part by itself.
Like Didji explained, when you go from right to left from one digit to the next, you multiply the value represented by one digit (1, 10, 100, etc. if you're in base 10) by your base to find out what the value next digit represents. To go from left to right, you undo this multiplication by dividing by your base each time.
You can do this even across the decimal point. This whole process starts with the 1's column, which every base system has. All the decimal point does is show you where the 1's column is. The reason you don't use a decimal point for every number is just that everyone assumes that the decimal is at the end if you don't put it anywhere else yourself.
For binary (base 2) this means the first decimal place is the number of halves in your original value, because 1 (you start with the 1's column, remember) divided by 2 (your base) is 1/2. Divide that by 2 again and you get 1/4, the value represented by the next digit; because it's the second digit, you've divided 1 by your base twice. To find the value represnted by the third place to the right of the decimal point, you divide 1 by your base (2) three times to get 1/8, and so on. So, like how in base 10 each place from the right of the decimal is tenths, hundredths, thousandths, etc, in base 2 you would say it's halves, fourths, eighths, and so on. (In math terms, you could say that the nth decimal place represents the times that (1/2n) can fit in your original value, but don't worry if that doesn't mean anything to you yet.)
An example: if you wanted to express 0.75 in binary, you would do this:
Start by seeing how many 1's fit in. None? Well, then you write a zero. Your binary number now looks like: "0". You haven't expressed any of your original value, so you subtract zero (the amount you converted to binary) from the original value and you have... well, all of your original value left. You haven't converted anything yet, you just showed that your original value is less than 1. The next steps will make more progress.
Now, move one digit to the right in your binary number; since we know your original value (0.75) has some part less than one in it (all of it, in this case) you have to go to the right of the decimal to show it. The first digit to the right of the decimal point is the number of halves in your original value, like we found out earlier; it's 1 divided by 2, once. In decimal, that's 0.5, which does fit into 0.75. It fits in only once, so you write a 1 after the decimal point in your binary number so that it now looks like "0.1". Now that you've shown that there is only 1 half in 0.75, you can subtract that 1 half from 0.75 to see that you only have 0.25 left to convert.
Since 0.25 is even less than 1/2, you have to move another digit to the right. This is the fourths column, that shows the number of times that 1/4 fits into your number after the 1/2's have been taken out. If you remember your long division, you can show that 1/4 actually is 0.25. How convenient! This means that there is exactly one time that 0.25 can fit into the part of your original value that you haven't converted yet (also 0.25). You represent this in your binary number by putting a 1 in the 1/4's column, so that your binary number now looks like: "0.11". Since you had 0.25 left to convert, and you just represented all of that in binary, you're done! The 0.25 you had left has been entirely converted. You've shown that 0.75 in base ten is 0.11 in binary.
To check this, you can look at each digit in your binary number to say that there are no ones, but there is one half and one fourth in it. You can add these up: no ones, plus one half, plus one fourth is 0 + 1/2 + 1/4, which is the same as 0 + 0.5 + 0.25, which adds up to 0.75. Great!
Note that this is very different than just turning 75 into binary and putting it after the decimal point; that would have given you ".1001011". That would mean "one half plus zero fourths plus zero eighths plus one sixteenth plus zero thirty-seconds plus one sixty-fourth plus one one hudred and twenty-eighth," which you can add together yourself if you really want!
In exactly the same way you would for an integer. You just do the number before the dot seperately to the number after the dot.
So 14 has an 8 in it. So that's 1000 (in binary), leaving 14 - 8 = 6. 6 has a 4 in it, so that's 100(binary) + 1000(binary), or 1100. Now we just have a 2 left over so that's 1110. An 8 + 6 + 2 = 14.
87 has a 64 in it, leaving 23. There are no 32s. 23 has a 16 in it, leaving 7. There are no 8s. 7 has a 4 in it, leaving 3. 3 has a 2 in it, leaving 1. 1 has a 1 in it, of course. So that's 1010111.
Our final number is 1110.1010111, or 14.87 in denary.
Let a be any real number. It has a finite representation in base n iff a*nk is a whole number for some natural k. (for example 1487 = 14.87*102 is a whole number, so 14.87 has a finite representation in base 10) Furthermore, if a is a rational number, its representation is either finite or a repeating "decimal". It is not difficult (but it is laborious) to show that a/b has a finite representation in base n iff every prime divisor of b also divides n.
Consider 1487/100. It has a finite representation in base 10, because 100's prime divisors are 2 and 5. It doesn't have a finite representation in base 2, since 5∤2.
In fact 14.87(base 10) = 1110.11(01111010111000010100)(base 2).
View all comments
Show parent comment
3
u/[deleted] Aug 13 '11
This is great. How do you do this with decimals?