AcademiaAgriculture & FarmingHumanitiesSocial SciencesSTEM

How to Convert a Number to Base-3

Updated on October 08, 2016
calculus-geometry profile image

TR Smith is a teacher and creator who uses mathematics in her line of work every day.

The base-3 numbering system is known as ternary, or less frequently trinary. In the ternary number system every number is represented as a string of 0s, 1s, and 2s. For example, the regular base-10 (decimal) number ninety-seven (97) is written as 10121 in ternary. Base-3 numbering is not as frequently used as binary, octal, or hexadecimal, however it has some unique uses and some interesting properties. To convert a base-10 number into base-3, you divide the number and successively divide the resulting quotients by 3 and then read the string of remainders from end to beginning.

Some examples of computing base-3 representations are worked out below along with some interesting properties of ternary numbers.

Converting to Base-3 with the Remainder Method

Let's convert the decimal number 4,517 as an example. The first step is to divide it by three and note the remainder. This gives us a quotient of 1,505 remainder 2.

Next, divide 1,505 by 3. This gives us a quotient of 501 remainder 2. Continuing, we get

501/3 = 167 remainder 0.

167/3 = 55 remainder 2.

55/3 = 18 remainder 1.

18/3 = 6 remainder 0.

6/3 = 2 remainder 0.

2/3 = 0 remainder 2.

Now if we read the list of remainders from bottom to top we get 20012022 as the base-3 representation of 4,517.

Second Example

Let's convert the base-10 number 507 to base-3.

  • 507/3 = 169 remainder 0
  • 169/3 = 56 remainder 1
  • 56/3 = 18 remainder 2
  • 18/3 = 6 remainder 0
  • 6/3 = 2 remainder 0
  • 2/3 = 0 remainder 2

Reading from bottom to top the base-3 representation is 200210.

Third Example

Let's convert the base-10 number 25,000 to ternary. Working out the successive remainders gives us

  • 25000/3 = 8333 remainder 1
  • 8333/3 = 2777 remainder 2
  • 2777/3 = 925 remainder 2
  • 925/3 = 308 remainder 1
  • 308/3 = 102 remainder 2
  • 102/3 = 34 remainder 0
  • 34/3 = 11 remainder 1
  • 11/3 = 3 remainder 2
  • 3/3 = 1 remainder 0
  • 1/3 = 0 remainder 1

Reading the list of remainders from bottom to top gives you 1021021221 as the base-3 representation of the decimal number twenty-five thousand.

Converting Base-3 Back to Base-10

To check that 1021021221 is the correct base-3 representation of 25,000, you convert the base-3 representation to the base-10 form and see if the answers match. To do this, take the digits of the base-3 form and multiply by the power of three that corresponds to its place, starting with 3^0 = 1 in the units place, 3^1 = 3 in the "tens" place, 3^2 = 9 in the "hundreds" place, 3^3 = 27 in the thousands place, etc. Then add them all up to obtain the base-10 form. With our example of 25,000 = 1021021221, this gives us

1*(3^9) + 0*(3^8) + 2*(3^7) + 1*(3^6) + 0*(3^5) + 2*(3^4) + 1*(3^3) + 2*(3^2) + 2*(3^1) + 1*(3^0) = 25,000.

Properties of Ternary Numbers

In base-10 you can tell whether or not a number is even by looking at the last digit -- it will be one of 0, 2, 4, 6, or 8. But this method doesn't work in base-3 since even numbers may end in either 0, 1, or 2. Instead, you count the number of 1's in the string. The ternary representation of an even number has an even number of 1s. That is, it will contain either zero, two, four, six,...etc. instances of the digit 1. Likewise, an odd number has an odd number of 1s.

Here are some other properties of base-3:

  • Every multiple of 3 ends in the digit 0.
  • Every multiple of 9 ends in the digits 00.
  • Every square number that is not a multiple of 3 ends in the digit 1. By extension, every even power ends in 1 unless the power is a multiple of 3.
  • It is conjectured (but not yet proven) that for every integer n greater than 15, the base-3 expansion of 2^n contains at least one of each digit.
  • The base-3 expansion of a number is approximately 2.0959 times longer, on average, than the base-10 expansion. In comparison to binary, the base-2 expansion is about 1.58496 times longer than the base-3 expansion, on average.
  • Every number of the form 3^n is represented by a 1 followed by n 0s.
  • Every number of the form 3^n - 1 is represented by a string of n 2s.
  • Every number of the form (3^n - 1)/2 is represented by a string of n 1s.
  • The first fifteen Fibonacci numbers in base-3 are 1, 1, 2, 10, 12, 22, 111, 210, 1021, 2001, 10022, 12100, 22122, 111222, and 211121.


Base-10 to Base-3 Conversions

Decimal
Ternary
 
Decimal
Ternary
 
Decimal
Ternary
1
1
 
13
111
 
25
221
2
2
 
14
112
 
26
222
3
10
 
15
120
 
27
1000
4
11
 
16
121
 
28
1001
5
12
 
17
122
 
29
1002
6
20
 
18
200
 
30
1010
7
21
 
19
201
 
31
1011
8
22
 
20
202
 
32
1012
9
100
 
21
210
 
33
1020
10
101
 
22
211
 
34
1021
11
102
 
23
212
 
35
1022
12
110
 
24
220
 
36
1100

So far this tutorial has only covered how to convert positive integers from decimal to ternary, but just as fractions and irrational numbers can be represented by base-10 decimal numbers, so can they be represented by base-3 "decimals." Here is a table of some common fractions and irrational numbers in their ternary forms. The part of the decimal in braces { } is repeated, while ellipses... indicate a non-repeating non-terminating string (aka, irrational number).

number
decimal
 
1/2, one half
0.5
0.{1}
1/3, one third
0.{3}
0.1
2/3, two thirds
0.{6}
0.2
1/4, one fourth
0.25
0.{02}
3/4, three fouths
0.75
0.{20}
1/5, one fifth
0.2
0.{0121}
2/5, two fifths
0.4
0.{1012}
1/6, one sixth
0.1{6}
0.0{1}
pi
3.141592653...
10.010211012...
e
2.718281828...
2.201101121...
square root of 2
1.414213562...
1.102011221...
square root of 3
1.732050807...
1.201202122...
phi, the golden ration
1.618033988...
1.121200112...

Irrational numbers have a non-repeating, non-terminating decimal expansion. If a number is irrational in base-10 it is irrational in any integer base. Rational numbers either terminate or repeat. Rational numbers in base-10 are still rational in base-3, but whether the expansion terminates or repeats may be different. In base-10, the decimal form of a rational number only terminates if the denominator is of the form (2^m)*(5^n) for some non-negative integers m and n, otherwise it repeats. In base-3, the decimal expansion only terminates if the denominator is of the form 3^n for some non-negative n, otherwise it repeats.

Practical Uses of Ternary

Most computing systems are two-state systems based on binary, with a bit being the smallest unit. A bit represents either an on or off state, corresponding to 1 and 0. In three-state systems, the smallest unit is a "trit" which takes on three values. The extra state is called a high-impedance state.

The ternary number system has the best average radix economy of any integer-base number system. Radix economy is defined as the number of digits needed to express an integer multiplied by the total number of digits available. The lower the number the more economical the system. The average number of digits needed to express a number in base-3 is log_3(K), where K is the number in question and log_3() is the logarithm base-3. Since ternary has three available digits, the radix economy is 3*log_3(K).


Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    Click to Rate This Article