|


Fraction/Decimal Conversion to Other BasesDate: 08/12/98 at 10:06:31 From: Celestine Trinidad Subject: Fraction conversion to other bases What are the rules for converting fractions to binary and octal and vice versa? I've searched the archives and I only saw questions pertaining to whole numbers. Thanks!
Date: 08/12/98 at 17:05:01
From: Doctor Peterson
Subject: Re: Fraction conversion to other bases
Hi, Celestine.
That's a good question. We tend to talk almost entirely about integers
when we discuss different bases, which leaves out a lot of good
information. I'm going to give you the whole picture: how to work with
both integers and fractions in other bases. What's interesting is that
you have to use different but sort of opposite methods for the integer
part of a number and the fraction part.
Of course, when I talk about fractions, I really mean what we would
call "decimals" for decimal numbers. To write an actual fraction in any
base, you would just write the ratio of two integers in that base. For
example, 7/10 in base 3 would be 21/101 (base 3). But I've never seen
anyone work with fractions that way. What's more useful is to write 0.7
(base 10) as 0.20022002... (base 3). I'm assuming that's what you want
to know about.
In general, any number can be written in base B as:
N = ... + a*B^3 + b*B^2 + c*B^1 + d*B^0 + e*B^-1 + f*B^-2 + ...
which is written as:
N = ...abcd.ef... (base B)
Note that there will of course be a first digit (highest power of B) at
the left, but, as in decimal, the fraction part may not terminate,
going on forever to the right. (The "decimal point" here is called the
"radix point," or sometimes as the "binary point," etc.)
How do we convert a number to and from such a base? I'll use base 3 for
my examples, rather than the unusually simple case of base 2.
First, converting from base 3 to base 10 is easy:
12.112 (base 3) = 1 * 3^1 + 2 * 3^0 + 1 * 3^-1 + 1 * 3^-2 + 2 * 3^-3
= 1 * 3 + 2 * 1 + 1 * .333 + 1 * .111 + 2 * .037
= 3 + 2 + .333 + .111 + .074
= 5.518... (base 10)
Another way to do this is simply to rewrite the number as a fraction:
12.112 (base 3) = 12112/1000 (base 3)
= (1*3^4 + 2*3^3 + 1*3^2 + 1*3^1 + 2*3^0) / 3^3
= (1 * 81 + 2 * 27 + 1 * 9 + 1 * 3 + 2 * 1) / 27
= (81 + 54 + 9 + 3 + 2) / 27
= 149/27
= 5.518... (base 10)
To do it with fewer multiplications or divisions, we can start at the
end farthest from the radix point and repeatedly multiply or divide by
the base and add in the next digit:
112 (base 3):
1: 1
1: (1) * 3 + 1 = 4
2: (4) * 3 + 2 = 14
.112 (base 3):
2: 2 / 3 = .666
1: (.666 + 1) / 3 = .555
1: (.555 + 1) / 3 = .518...
This calculates 112.112 (base 3) as:
((((1)*3 + 1)*3) + 2) + ((((2)/3 + 1)/3 + 1)/3
The algorithm for converting a number from base 10 to another base is
a little more complicated, but easy to do.
Let's start not with base 3 but with the more familiar case of a
decimal number, to see how it works to "convert" decimal to decimal.
How can we extract one decimal digit at a time from a number? If we
divide the number by 10, the remainder is the rightmost decimal digit
of the number, and the quotient is the left side of the number "slid
to the right one place." So we just repeat this process until there
are no more digits left:
1438 / 10 = 143 rem 8 -------------------------------> 8
^
143 / 10 = 14 rem 3 ---------------------> 3
^
14 / 10 = 1 rem 4 ------------> 4
^
1 / 10 = 0 rem 1 ---> 1
^
This process gives us each digit, starting at the decimal point and
moving left, by sliding the number to the right each time. Think of it
as a machine that chews up our (integer) number starting at the right
end, and spits out one digit after another.
To see the digits to the right of the decimal point, we have to "slide
the number to the left" instead, and we do that by _multiplying_ by
10. Then the integer part of the result is the leftmost digit of the
fraction, and the fraction part is the rest of the number "slid to the
left":
.4896 * 10 = 4.896; integer part -------------------------> 4
^ ^
.896 * 10 = 8.96; integer part -------------> 8
^ ^
.96 * 10 = 9.6; integer part --> 9
^ ^
.6 * 10 = 6.0; ----> 6
So this process is a machine that chews up a fractional number (it has
to be less than one to work) from the left, and spits out digits
starting to the right of the point.
To convert a decimal fraction to another base, say base 3, you do the
same thing, using 3 instead of 10. You split it into an integer and a
fractional part. Then divide the integer part by 3 repeatedly to get
each digit as a remainder, and then multiply the fractional part by 3
repeatedly to get each digit as an integer part. Let's convert 14.3
(decimal) to base 3:
First convert 14:
.
14 / 3 = 4 rem 2 ----------------------------------> 2
4 / 3 = 1 rem 1 --------------------------> 1
1 / 3 = 0 rem 1 ------------------> 1
Now convert 0.3:
.
0.3 * 3 = 0.9 -------------------------------------> 0
.9 * 3 = 2.7 ---------------------------> 2
.7 * 3 = 2.1 -----------------> 2
.1 * 3 = .3 --------> 0
Both lists of digits start at the radix point and move away, the
integer part to the left and the fraction part to the right. So the
answer is:
112.0220... (base 3)
Notice that 0.3 (base 10) terminates, but in base 3 it repeats with a
cycle of 4 digits.
Obviously, for binary you would do the same thing using 2 instead of
3, and for octal you would use 8.
Let me know if anything isn't clear.
- Doctor Peterson, The Math Forum
Check out our web site! http://mathforum.org/dr.math/
Date: 08/16/98 at 08:32:47
From: Jim Trinidad, MD, FPCS
Subject: Re: fraction conversion to other bases
Thanks for your reply. It really helped me a lot in my lessons. Your
site is really cool. It makes math really easy to understand.
Celestine G. Trinidad from the Philippines
|
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]


Ask Dr. MathTM
© 1994-2008 The Math Forum
http://mathforum.org/dr.math/