Associated Topics || Dr. Math Home || Search Dr. Math

### Fraction/Decimal Conversion to Other Bases

```
Date: 08/12/98 at 10:06:31
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

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

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
Subject: Re: fraction conversion to other bases

site is really cool. It makes math really easy to understand.

Celestine G. Trinidad from the Philippines
```

```Date: 09/26/2014 at 19:39:49
From: Luke
Subject: Converting 112 [Base 3] to Base 10

Hi Dr. Peterson,

I'm trying to understand a section of a previous explanation on your
website.

I was looking for info on base numbers when I came upon this page, which

However, I'm having trouble understanding the "1: 1." Why is the 1 by
itself?

If you could help me understand it I would be most appreciative.

Luke Towers
```

```Date: 09/26/2014 at 20:56:51
From: Doctor Peterson
Subject: Re: Converting 112 [Base 3] to Base 10

Hi, Luke.

I just meant, as I said above that line, "we can start at the end farthest
from the radix point"; in this case, we start with 1. I put it on a line
by itself because there is no work to be done until we bring in the next
digit: if 1 were the only digit, we would be finished!

On the next line, we bring in the next digit, and the result, 4, is the
value of 11_3. Then we bring in the next digit, and the result is the
value of 112_3. Each time we process a new digit, we do a calculation
starting with the value we had previously; for the first digit, we had no
value previously, so there is nothing to do.

I wrote that page long ago, and recently realized that one way to organize
that work for whole numbers is to use synthetic division. Finding the
value of 112_3 is equivalent to evaluating this polynomial for x = 3 (the
base):

1x^2 + 1x + 2

One way to evaluate this is to do just what it says. But another is to use
synthetic division to divide 1x^2 + 1x + 2 by (x - 3):

3 | 1  1   2
|    3  12
+---------
1  4  14
^^

[If you are not familiar with synthetic division, we bring down the 1,
then multiply it by 3 and put that on the second line, then add it to 1
and put 4 on the bottom line. Then we multiply that by 3, put 12 on the
second line, and add 2 + 12 = 14 for the answer.]

If you work through this, you will see that the work is identical to what
I did in the example; you will also notice that the 1 is alone, with
nothing else in its column!

Does that help at all?

- Doctor Peterson, The Math Forum

```

```Date: 09/26/2014 at 22:52:54
From: Luke
Subject: Thank you (Converting 112 [Base 3] to Base 10)

Hi!

Thanks for the very quick reply and the extra strategy. I see it now.

Thanks again.

- Luke

```
Associated Topics:
High School Number Theory

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search