Balanced Ternary Converter

Convert integers to and from balanced ternary using digits T (−1), 0 and 1.

Ad placeholder (leaderboard)

Convert numbers to and from balanced ternary

The Balanced Ternary Converter translates ordinary decimal integers into balanced ternary — the elegant base-3 system whose digits are −1, 0 and +1 — and back again. Negative numbers are handled naturally, with no sign bit and no minus symbol, because the digit set is symmetric around zero.

How it works

To convert a positive integer to balanced ternary, repeatedly divide by 3 and inspect the remainder:

remainder 0 -> digit 0
remainder 1 -> digit 1
remainder 2 -> digit T (-1), and add 1 carry to the quotient

The carry on a remainder of 2 is the key trick: since 2 = 3 − 1, you write −1 in this position and bump the next position up by one. Reading the recorded digits from last to first gives the balanced ternary value. To convert back, evaluate the string left to right with total = total × 3 + digit, where T is −1.

Negation is free: swap every 1 with T and every T with 1. That is why the converter handles negative inputs by converting the absolute value and flipping the digits.

Example

Decimal 2 has remainder 2 when divided by 3, so the digit is T and a carry of 1 is added, making the next quotient 1. The result is 1T, which evaluates as 1×3 + (−1)×1 = 2. Decimal −2 is simply T1, the digit-flipped form.

Notes

Balanced ternary truncation rounds to the nearest value, a property that makes it appealing for certain arithmetic and the reason it powered the experimental Setun computer. The converter limits input to safe integers so the repeated division stays exact.

Ad placeholder (rectangle)