Balanced Ternary Number System
As we already know, a Binary number system is a number system that has only 2 digits in it, i.e. 0 and 1. Similarly, we also know that a Ternary number system is a number system that has only 3 digits in it, i.e. 0, 1, and 2. In this article, we will learn about Balanced Ternary Number System.
A balanced ternary number system is a numeral system that comprises digits -1, 0, and 1. Since it is inconvenient to write -1 as a digit, we’ll use the letter Z further for this purpose.
Conversion of Decimal to Balanced Ternary system
The conversion from Decimal to balanced ternary is done in two steps:
- Convert decimal to the ternary number system.
- Convert ternary to the balanced ternary system, using the below steps:
- traverse the ternary number, right to left by leaving 0 and 1 as it is
- when encounter 2, change it to Z and add +1 to the next digit in iteration.
- Some digits may become +3, then replace +3 with 0 and add +1 to next digit in iteration.
- complete this process until you convert all the digits.
Example: convert 23810 to balanced ternary and vice-versa
First convert 23810 to ternary number system.
23810 = 222113
Second convert ternary to balanced ternary number system :
- By starting iteration from right to left, two 1’s are skipped as it remains same in balanced ternary.
- Now convert first encountered 2 with z increasing it’s next digit in iteration by +1. So we get 23Z11.
- Convert 3 to 0 with increment +1 in it’s next digit in iteration. So we get 30Z11.
- Convert 3 to 0 with increment +1 in it’s next digit in iteration. So we get 100Z11. (Here assume 0 is present before most significant digit)
The final result is 100Z11.
Note: The system also allows representation of negative numbers eliminating the need for a negative sign before the number. All negative numbers in a balanced ternary system start with Z. i.e.−110 = Z3, −210 = Z13, −310 = Z03, −410 = ZZ3, −510 = Z113
Below is the program to convert positive decimals into the balanced ternary system:
Equivalent Balanced Ternary of 238 is: 100Z11
Time Complexity: O(log3n)
Auxiliary Space: O(log3n)
Please Login to comment...