# Ternary numeral system

Part of a series on :
Numeral systems :
Place-value notation
Hindu–Arabic numerals
Western Arabic
Eastern Arabic
Bengali
Devanagari
Gujarati
Gurmukhi
Odia
Sinhala
Tamil
Malayalam
Telugu
Kannada
Dzongkha
Tibetan
Balinese
Burmese
Javanese
Khmer
Lao
Mongolian
Sundanese
Thai
East Asian systems
Contemporary
Chinese
Hokkien
Suzhou
Japanese
Korean
Vietnamese
Historic
Counting rods
Tangut
Other systems
History
Ancient
Babylonian
Post-classical
Cistercian
Mayan
Muisca
Pentadic
Quipu
Rumi
Contemporary
Cherokee
Kaktovik (Iñupiaq)
By radix/base
Common radices/bases
2
3
4
5
6
8
10
12
16
20
60
Non-standard radices/bases
Bijective (1)
Signed-digit (balanced ternary)
Mixed (factorial)
Negative
Complex (2i)
Non-integer (φ)
Asymmetric :
Sign-value notation
Non-alphabetic
Aegean
Attic
Aztec
Brahmi
Chuvash
Egyptian
Etruscan
Kharosthi
Prehistoric counting
Proto-cuneiform
Roman
Tally marks
Alphabetic
Abjad
Armenian
Alphasyllabic
Akṣarapallī
Āryabhaṭa
Kaṭapayādi
Coptic
Cyrillic
Geʽez
Georgian
Glagolitic
Greek
Hebrew :
List of numeral systems :
vte :
A ternary /ˈtɜːrnəri/ numeral system (also called base 3 or trinary) has three as its base. Analogous to a bit, a ternary digit is a trit (trinary digit). One trit is equivalent to log$_2$ 3 (about 1.58496) bits of information.
Although ternary most often refers to a system in which the three digits are all non–negative numbers; specifically 0, 1, and 2, the adjective also lends its name to the balanced ternary system; comprising the digits −1, 0 and +1, used in comparison logic and ternary computers.

## Comparison to other bases

Representations of integer numbers in ternary do not get uncomfortably lengthy as quickly as in binary. For example, decimal 365$_{(10)}$ or senary 1405$_{(6)}$ corresponds to binary 101101101$_{(2)}$ (nine bits) and to ternary 111112$_{(3)}$ (six digits). However, they are still far less compact than the corresponding representations in bases such as decimal – see below for a compact way to codify ternary using nonary (base 9) and septemvigesimal (base 27).
A ternary multiplication table :
| × | 1 | 2 | 10 | 11 | 12 | 20 | 21 | 22 | 100 |
| 1 | 1 | 2 | 10 | 11 | 12 | 20 | 21 | 22 | 100 |
| 2 | 2 | 11 | 20 | 22 | 101 | 110 | 112 | 121 | 200 |
| 10 | 10 | 20 | 100 | 110 | 120 | 200 | 210 | 220 | 1,000 |
| 11 | 11 | 22 | 110 | 121 | 202 | 220 | 1,001 | 1,012 | 1,100 |
| 12 | 12 | 101 | 120 | 202 | 221 | 1,010 | 1,022 | 1,111 | 1,200 |
| 20 | 20 | 110 | 200 | 220 | 1,010 | 1,100 | 1,120 | 1,210 | 2,000 |
| 21 | 21 | 112 | 210 | 1,001 | 1,022 | 1,120 | 1,211 | 2,002 | 2,100 |
| 22 | 22 | 121 | 220 | 1,012 | 1,111 | 1,210 | 2,002 | 2,101 | 2,200 |
| 100 | 100 | 200 | 1,000 | 1,100 | 1,200 | 2,000 | 2,100 | 2,200 | 10,000 |
    Numbers from 0 to 3$^3$ − 1 in standard ternary Ternary 012101112202122 Binary 0110111001011101111000 Senary 012345101112 Decimal 012345678 Ternary 100101102110111112120121122 Binary 1001101010111100110111101111 1000010001 Senary 131415202122232425 Decimal 91011121314151617 Ternary 200201202210211212220221222 Binary 1001010011101001010110110 10111110001100111010 Senary 303132333435404142 Decimal 181920212223242526
    Powers of 3 in ternary Ternary 110100100010000 Binary 1111001110111010001 Senary 131343213 Decimal 1392781 Power 3$^0$3$^1$3$^2$ 3$^3$3$^4$ Ternary 100000100000010000000 1000000001000000000 Binary 111100111011011001100010001011 1100110100001100110011100011 Senary 104332131404350213231043 Decimal 2437292187656119683 Power 3$^5$3$^6$3$^7$ 3$^8$3$^9$
As for rational numbers, ternary offers a convenient way to represent ⁠1/3⁠ as same as senary (as opposed to its cumbersome representation as an infinite string of recurring digits in decimal); but a major drawback is that, in turn, ternary does not offer a finite representation for ⁠1/2⁠ (nor for ⁠1/4⁠, ⁠1/8⁠, etc.), because 2 is not a prime factor of the base; as with base two, one-tenth (decimal⁠1/10⁠, senary ⁠1/14⁠) is not representable exactly (that would need e.g. decimal); nor is one-sixth (senary ⁠1/10⁠, decimal ⁠1/6⁠).
    Fractions in ternary Fraction ⁠1/2⁠⁠1/3⁠⁠1/4⁠⁠1/5⁠⁠1/6⁠⁠1/7⁠⁠1/8⁠⁠1/9⁠⁠1/10⁠⁠1/11⁠⁠1/12⁠⁠1/13⁠ Ternary 0.10.10.020.01210.010.0102120.010.010.00220.002110.0020.002 Binary 0.10.010.010.00110.0010.0010.0010.0001110.000110.00010111010.00010.000100111011 Senary 0.30.20.130.10.10.050.0430.040.030.03134524210.030.024340531215 Decimal 0.50.30.250.20.160.1428570.125 0.10.10.090.0830.076923

### Sum of the digits in ternary as opposed to binary

The value of a binary number with n bits that are all 1 is 2$^n$ − 1.
Similarly, for a number N(b, d) with base b and d digits, all of which are the maximal digit value b − 1, we can write:
    N(b, d) = (b − 1)b$^{d−1}$ + (b − 1)b$^{d−2}$ + … + (b − 1)b$^1$ + (b − 1)b$^0$,
    N(b, d) = (b − 1)(b$^{d−1}$ + b$^{d−2}$ + … + b$^1$ + 1),
    N(b, d) = (b − 1)M.
    bM = b$^d$ + b$^{d−1}$ + … + b$^2$ + b$^1$ and
    −M = −b$^{d−1}$ − b$^{d−2}$ − ... − b$^1$ − 1, so
    bM − M = b$^d$ − 1, or
    M = ⁠b$^d$ − 1/b − 1⁠.
Then
    N(b, d) = (b − 1)M,
    N(b, d) = ⁠(b − 1)(b$^d$ − 1)/b − 1⁠,
    N(b, d) = b$^d$ − 1.
For a three-digit ternary number, N(3, 3) = 3$^3$ − 1 = 26 = 2 × 3$^2$ + 2 × 3$^1$ + 2 × 3$^0$ = 18 + 6 + 2.

### Compact ternary representation: base 9 and 27

Comparison between ternary and nonary :
| ternary | nonary |
| 00 | 0 |
| 01 | 1 |
| 02 | 2 |
| 10 | 3 |
| 11 | 4 |
| 12 | 5 |
| 20 | 6 |
| 21 | 7 |
| 22 | 8 |
Nonary /ˈnɒnəri/ (base 9, each digit is two ternary digits) or septemvigesimal (base 27, each digit is three ternary digits) can be used for compact representation of ternary, similar to how octal and hexadecimal systems are used in place of binary.

## Practical usage

In certain analog logic, the state of the circuit is often expressed ternary. This is most commonly seen in CMOS circuits, and also in transistor–transistor logic with totem-pole output. The output is said to either be low (grounded), high, or open (high-Z). In this configuration the output of the circuit is actually not connected to any voltage reference at all. Where the signal is usually grounded to a certain reference, or at a certain voltage level, the state is said to be high impedance because it is open and serves its own reference. Thus, the actual voltage level is sometimes unpredictable.
A rare "ternary point" in common use is for defensive statistics in American baseball (usually just for pitchers), to denote fractional parts of an inning. Since the team on offense is allowed three outs, each out is considered one third of a defensive inning and is denoted as .1. For example, if a player pitched all of the 4th, 5th and 6th innings, plus achieving 2 outs in the 7th inning, his innings pitched column for that game would be listed as 3.2, the equivalent of 3+2⁄3 (which is sometimes used as an alternative by some record keepers). In this usage, only the fractional part of the number is written in ternary form.
Ternary numbers can be used to convey self-similar structures like the Sierpinski triangle or the Cantor set conveniently. Additionally, it turns out that the ternary representation is useful for defining the Cantor set and related point sets, because of the way the Cantor set is constructed. The Cantor set consists of the points from 0 to 1 that have a ternary expression that does not contain any instance of the digit 1. Any terminating expansion in the ternary system is equivalent to the expression that is identical up to the term preceding the last non-zero term followed by the term one less than the last non-zero term of the first expression, followed by an infinite tail of twos. For example: 0.1020 is equivalent to 0.1012222... because the expansions are the same until the "two" of the first expression, the two was decremented in the second expansion, and trailing zeros were replaced with trailing twos in the second expression.
Ternary is the integer base with the lowest radix economy, followed closely by binary and quaternary. This is due to its proximity to the mathematical constant e. It has been used for some computing systems because of this efficiency. It is also used to represent three-option trees, such as phone menu systems, which allow a simple path to any branch.
A form of redundant binary representation called a binary signed-digit number system, a form of signed-digit representation, is sometimes used in low-level software and hardware to accomplish fast addition of integers because it can eliminate carries.

### Binary-coded ternary

Simulation of ternary computers using binary computers, or interfacing between ternary and binary computers, can involve use of binary-coded ternary (BCT) numbers, with two or three bits used to encode each trit. BCT encoding is analogous to binary-coded decimal (BCD) encoding. If the trit values 0, 1 and 2 are encoded 00, 01 and 10, conversion in either direction between binary-coded ternary and binary can be done in logarithmic time. A library of C code supporting BCT arithmetic is available.

### Tryte

Some ternary computers such as the Setun defined a tryte to be six trits or approximately 9.5 bits (holding more information than the de facto binary byte).