Converting Floating Decimals to Other BasesDate: 11/27/2003 at 09:46:06 From: Ferran Subject: Floating Base Conversions Hi, how can I convert between bases but preserve the decimal places? For example: 123.5 (decimal) = 7B.8 (Hexadecimal) 123.5 (decimal) = 1111011.1 (Binary) I got these results from a calculator. How are the operations done? Date: 11/29/2003 at 22:09:06 From: Doctor Mike Subject: Re: Floating Base Conversions Hello Ferran, Clearly from your example you already have some familiarity with hexadecimal representation. By your example it seems you may be interested in converting the fractional part of a number into hex. To see how that is done, think about what the fractional part of a hex number means: The number 0.5C31 means 5/16 + 12/16^2 + 3/16^3 + 1/16^4. If you multiply that by 16, you get 5 + 12/16 + 3/16^2 + 1/16^3, which is the same as 5.C31 in hex. Do you see what is happening? Remember that for decimals in base ten, multiplying by 10 moves the "point" one place to the right. In hexadecimal it is the same, in a way. If you multiply a hexadecimal representation number by "10 hex" (which is decimal 16) you move the point one place to the right. So, .5C31 times "10 hex" becomes 5.C31. The "5" which used to be the first hex digit to the right of the point is now the whole number part. If you subtract off the 5 then the result is another fractional part 0.C31, and you can do the same thing all over again. To review, the steps are: 1. Multiply the base ten fractional part by 16. 2. Use the whole number part of this as the next hex digit 3. Subtract off this whole number part, leaving a new fractional part. 4. If this fractional part is 0.0 you are done; if it's not, go back to step 1 and continue. This repetitive process gives you the hex digits corresponding to the base 10 digits in the original fractional decimal. Here is an example: In base ten 1/9 = 0.1111111111111111111111... Let's convert that to hexadecimal notation. Here are the steps: * Multiply 0.11111111111111... by 16 to get 1.77777777777777... * The whole number part is "1" so that is the first hex digit. * Subtract 1 to get a new fractional part 0.77777777777777... * Multiply 0.77777777777777... by 16 to get 12.44444444444444... * The whole number part is "12" or "C" for the next hex digit. * Subtract 12 to get a new fractional part 0.44444444444444... * Multiply 0.44444444444444... by 16 to get 7.11111111111111... * The whole number part is "7" so that is the third hex digit. * Subtract 7 to get a new fractional part 0.11111111111111... * Multiply 0.11111111111111... by 16 to get 1.77777777777777... and you see we are back where we started, so the hex decimal is going to be an infinitely repeating one 0.1C71C71C7... just like the original 0.111111111... was. Neat, eh! Notice that the whole numbers 1 and 9 are the same in hexadecimal as they are in base ten, so we can write the following in hex: 1/9 = 0.1C71C71C7... Another interesting example is "pi minus 3", using the famous real number pi. Pi minus 3 is approximately 0.14159265358979324 and if you follow this procedure 12 times, you get "pi - 3" in hexadecimal accurate to 12 places, namely, 0.243F6A8885A3. You will probably want to use a calculator!! Adding back in the 3, you get a really good approximation for pi in hexadecimal: pi = 3.243F6A8885A3... I enjoyed thinking about this. I hope you did, too. - Doctor Mike, The Math Forum http://mathforum.org/dr.math/ Date: 11/30/2003 at 04:22:11 From: Ferran Subject: Thank you (Floating Base Conversions) Thanks so much for the explanation. Finally I can see the light! |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/