The base-3 positional numeral system which represents numbers using the digits 0, 1, and 2
Ternary is the base-3 positional numeral system which represents numbers using the digits 0, 1, and 2. In computing it is less common than binary, but there have been ternary computers, and it can be used to represent sequences of ternary (3-way) choices.
A unit of information in the ternary numeral system is sometimes called a trit (by analogy with bit for binary).
Number systems:
Name | Base | numbers
------------------------------------------
ternary - system | 2 | 0... 2
decimal - system | 10 | 0... 9
ternary | decimal
-----------------------
0 | 0
1 | 1
2 | 2
10 | 3
11 | 4
12 | 5
20 | 6
21 | 7
22 | 8
30 | 9
101 | 10
121 | 16
1012 | 32
2101 | 64
11202 | 128
100110 | 255
Decimal -> Ternary
Number: 42
42 / 3 = 14 Rest 0 ^
14 / 3 = 4 Rest 2 |
4 / 3 = 1 Rest 1 |
1 / 3 = 0 Rest 1 | => 42 = 1120
----->
Ternary -> Decimal
Number: 1120
1 1 2 0
| | | -------- 0 x 3^0 -> 0
| | ----------- 2 x 3^1 -> 6
| -------------- 1 x 3^2 -> 9
----------------- 1 x 3^3 -> 27
= 42
- Other numeral systems: binary (base 2), ternary (base 3), octal (base 8), decimal (base 10), hexadecimal/hexadecimal-notation (base 16)
- The balanced ternary numeral system
- "Ternary" can also mean a function or operator that takes 3 operands. See ternary-operator, or conditional-operator for the most common ternary operator.
- "Ternary" can also describe 3-way branches. For ternary data structures and algorithms, see ternary-tree, ternary-search-tree, ternary-search, or quicksort.