
Ternary system emulation. Option concept
1. Prologue
Recently I read a wonderful article [1] . In it, the author talks about the fact that computers were not always binary. At the dawn of the computer era, there were machines that used the decimal and ternary number systems.
The decimal system is convenient for humans, but it is quite difficult to implement on the existing elemental base. In addition, the decimal system is prone to errors due to signal distortion during transmission. Implementing a ternary system is not much more complicated than binary ( [2] ), but it can give at least three advantages.
Firstly, the representation of negative numbers becomes natural. Since the smallest unit of information in the ternary system (we will call it trit) is capable of taking three possible values, it becomes possible to represent zero and a positive number in different ways.
Secondly, a trait (a set of eight trits) is capable of taking values in the range of ± 3,280, including zero, which is approximately thirteen times the number of possible values of a byte in the range of only positive numbers (a byte cannot fundamentally take negative values without introducing special conventions )
Thirdly, trit is able to take the value “not defined”, which is closer to the model of human thinking than the combination of binary values “true” and “false”.
The purpose of the article is to propose a method for implementing basic logical operations with ternary values using a binary computing system.
2. Ternary-binary conversion
The first thing we need to do is find a method for representing ternary numbers in a binary computer system. As already mentioned, trit is able to take three logical meanings: “false”, “not defined” and “truth”. Three possible values can be represented by two bits, but unlike the binary system, the bits here are not equal.
Let the first bit determine the logical values “true” and “false”. The second bit (half) is the control. The certainty of the value of the trit depends on its value. If half-tritis is set, the value of trit is determined; if reset, it is not defined.
Thus, two bytes are needed to represent the trait. The simplest implementation is to “collect” control half-trits into one byte, and all “significant” half-trits into another.
The final value of the trit is determined according to the following algorithm: the value of one-half from the control byte is analyzed. If it is false, the value of the trit becomes "not defined", otherwise the value of the trit becomes the value of the significant half-trit.
Example:
Let a trit in a trait can take one of the following values:
1 - "true"
-1 - "false"
0 - "not defined"
Significant byte 0010 1100
Control byte 1100 1010
Trait -1-100 10-10
In binary system trait can be represented as follows:
01011000 11100100
Thus, binary analogues of ternary values will have: Note:
1t = 10b ~ «истина»
0t = 00b ~ «не определено»
0t = 10b ~ «не определено»
-1t = 01b ~ «ложь»
As you can see the value "not defined" can be represented in two ways. This is due to the redundancy of the possible values of two bits to represent one trit.
3. Ternary logic operations
In binary logic, there are five basic operations that cannot be expressed through each other:
1. Negation ("NOT", ~);
2. Repetition (“REP”);
3. Conjunction ("AND", &);
4. Disjunction ("OR", |);
5. The shift ("<<" and ">>").
In parentheses are the designations of operations accepted in the C programming language (except for item 2, since there is no repetition operation in C - author's note ).
In the second part, it was said that the analysis of the value of trit begins with the analysis of the value of half-trit. If its value is “not defined”, it does not make sense to analyze the second half-trit - the value of the entire trit becomes “not defined”. If the value of the trit is determined, logical operations are applied to the trit in the same way as bits.
Example:
-1011 -1-1-10 & 000-1 11-10
Imagine the traits in the binary system: Divide the traits into control and significant bytes (ST - significant byte, UB - control byte) : We perform the operation as with binary bytes: The shift is performed similarly, only it should be taken into account that the shift operation is performed on the trit, which in the binary system is denoted by two bits. In other words:
-1011 -1-1-10 = 01001111 01010100
000-1 11-10 = 00000001 11110100
01001111 01010100 = 0011 0000 (ЗБ) 0011 1110 (УБ)
00000001 11110100 = 0000 1100 (ЗБ) 0001 1110 (УБ)
0000 0000 (ЗБ) 0001 1110 (УБ) = 00000001 01010100 = 000-1 -1-1-10
-1011 -1-1-10 >> 2 = 01001111 01010100 >> 4 = 00000100 11110101 = 00-10 11-1-1
4. Trinity arithmetic
The laws of ternary arithmetic are similar to the laws of mathematics for the ternary number system. For the convenience of representing numbers, it is worth accepting that Thus, the algebra of logic is very different from computational algebra. To indicate the sign of a number, a half-digit with a value of "11" will be used in the same way as in the binary representation of a negative number. Note: At the beginning of the article, I intentionally made a mistake. Now it is obvious that the value of one trait lies in the range of ± 1,143, which nevertheless is almost 9 times larger than the range of ± 128.
0t = 00b
1t = 01b
2t = 10b
4. Conclusion
In the article, I tried to briefly and as much as possible provide my vision of the implementation of ternary computing on binary systems. Of course, without hardware support, ternary logic and arithmetic can be more fun than finding serious use.
Systems with a very different architecture from Intel exist now. Perhaps someday, in order to reduce costs and increase productivity, the giants of the global digital industry will turn to the development of the 50s: the idea of an automatic computer was born many centuries before the appearance of a torn computer.
PS The post expresses the author’s point of view and in no way claims to be an effective implementation or the title of truth.