# How to convert a fraction into ternary?

In a ternary system how is $\dfrac{1}{2}=0.\bar1$ ,$\dfrac{1}{3}=0.1=0.0\bar2$??, etc. In general, how does one write the ternary expression for a given fraction?

-
Do long division as you learned to do it in third grade, only using base three instead of base ten. –  Henning Makholm Oct 6 '11 at 16:15
But in these days of calculators, do they teach long division in third grade any more? –  GEdgar Oct 6 '11 at 16:26
@GEdgar: Interesting question, so I did some digging. For Washington state, where I live, long division is part of the 5th grade math standards, but not for any of the earlier grades. I remember learning long division in 3rd grade as well. Maybe they've just moved it to the higher grade levels? –  Mike Spivey Oct 6 '11 at 19:57

I assume you know how to convert integers from base 10 to base 3, so this answer will address fractions between $0$ and $1$.

To say, for example, that $\frac{5}{8} = 0.625$ means that $\frac{5}{8} = 6 \frac{1}{10} + 2 \frac{1}{100} + 5 \frac{1}{1000}$. So to convert a fraction $\frac{a}{b}$ to ternary means we want to find coefficients $c_1, c_2, c_3, \ldots$ such that $$\frac{a}{b} = c_1 \frac{1}{3} + c_2 \frac{1}{3^2} + c_3 \frac{1}{3^3} + \cdots.$$

Finding these coefficients can be automated. In fact, what follows is exactly the long division algorithm taught in elementary school for converting fractions to decimals, adapted to base 3. (You could also simply convert everything to base 3 first and then do long division, as is mentioned in the comments. For the algorithm described below, though, all the calculations can be done in base 10, which is nice since we're used to working in base 10.)

To find $c_1$, multiply the equation above by $3$ to obtain $$\frac{3a}{b} = c_1 + c_2 \frac{1}{3} + c_3 \frac{1}{3^2} + \cdots .$$ Divide $b$ into $3a$ to get $\frac{3a}{b} = \frac{qb + r}{b}$, with $q$ the quotient and $r$ the remainder. The quotient $\frac{qb}{b} = q$ will equal $c_1$, the integer part of the right-hand side, and $\frac{r}{b}$ will be the fractional part; i.e., $$\frac{r}{b} = c_2 \frac{1}{3} + c_3 \frac{1}{3^2} + \cdots.$$ Then multiply by $3$ again, and repeat the procedure until it terminates or starts repeating itself.

In tabular form and applied to $\frac{5}{8}$, this process looks like the following, where the numerator of the fraction in each line comes from $3r$ in the previous line.

$$\begin{matrix} \text{current fraction } & \text{quotient } q & \text{remainder } r & 3r \\ \frac{5}{8} & 0 & 5 & 15 \\ \frac{15}{8} &1 & 7 & 21\\ \frac{21}{8} &2 & 5 & 15\\ \frac{15}{8} &1 & 7 & 21\\ \frac{21}{8} &2 & 5 & 15\\ \vdots & \vdots & \vdots & \vdots \\ \end{matrix}$$ The base 3 representation comes from the quotients, so $\frac{5}{8}$ in ternary must be $0.\overline{12}_3$.

So why is this equivalent to long division? With long division, after finding a quotient and a remainder in a particular step, you then "carry down the $0$," which entails concatenating a $0$ on the end of the remainder. Mathematically, adding a $0$ on the end of a number in base 10 means that you are multiplying it by $10$. Since we're working in base 3 here, we want to multiply the remainder by $3$. That's the only difference between what I've said here and the long division algorithm taught in elementary school.

-
Thanks for the solution. –  Ramana Venkata Oct 7 '11 at 1:55
probably should be 6/10 + 2/100, not =. –  zzzzBov Oct 16 '14 at 14:34
@zzzzBov: Good catch! I'll fix it. –  Mike Spivey Oct 16 '14 at 16:12

The easiest way to do it, I think, is to convert everything before the decimal point the regular way. Then you just repeat the following process:

1. Subtract 1 until you get between 0 and 1.
2. Multiply by 3.
3. The integer part of your answer is the next digit of the ternary expansion.
4. Rinse and repeat.

Example, using $\frac{15}{4}$:

The integer part is 3, so we write $10_3$. We're now left with $\frac{3}{4}$. Multiply by 3 to get $\frac{9}{4}$, having an integer part of 2. So we have $10.2_3$. Subtract the 2 from the $\frac{9}{4}$, and we have $\frac{1}{4}$. Multiply by 3, we get $\frac{3}{4}$. This has no integer part, so the current result is $10.20_3$. Now, this will repeat, as is obvious, so the end result is $10.\overline{20}_3$.

Now, as to why this works, it is just a visualizing of trying to express the decimal part by fractions with denominator a power of 3. Which is what ternary decimal expansion is.

Edit: I realize that this answer is pretty darn equal to Mike Spivey's, and mine is much less precise and stuff. Sorry about that.

-
I prefer this way of looking at things, ’cause you don’t do anything that looks like division, not even like Euclidean division. You can even program your HP15C to do it. –  Lubin Nov 10 '12 at 21:13