Tool for converting, calculating and manipulating numbers in ternary code (base 3): decimal ↔ base 3 conversions, arithmetic operations, fractions and ternary logic.
Ternary Code (Base 3) - dCode
Tag(s) : Arithmetics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
To convert text, use a letter-number relationship such as A=1, B=2, etc., or the ASCII code (A=65).
Ternary (base 3) is a number system that uses three distinct symbols, usually $0$, $1$, and $2$, to represent numbers.
Each position in a ternary number corresponds to a power of $3$, allowing for the unique encoding of whole or fractional values.
The three standard base-3 symbols are 0, 1, and 2. Some systems use variants such as 1, 2, and 3 or A, B, and C.
In standard (ternary) base 3, the symbols are $ 0 $, $ 1 $ et $ 2 $.
In balanced ternary, the possible values are $ -1, 0, +1 $, which are often written as $ -, 0, + $, but also sometimes $ 0 $, $ 1 $ and $ T $.
Balanced ternary code is a variant that uses the values -1, 0, +1, allowing negative numbers to be represented without a separate sign.
This is not a simple replacement of 0, 1, and 2 with -1, 0, and 1; a different mathematical transformation must be applied.
To convert an integer (base 10 decimal) $ N $ to base 3, successively divide $ N $ by $ 3 $ and note the remainders (which are $ 0 $, $ 1 $, or $ 2 $).
Repeat until you obtain a quotient of zero. The remainders, read from bottom to top, give the base-3 representation.
Example: $ 42_{(10)} = 1120_{(3)} $
Convert the absolute value of the number to base 3, then add a minus sign - in front of the result.
Using balanced ternary code allows you to encode negative numbers without a minus sign.
To convert a number from base 3 to base 10, multiply each digit by 3 raised to the power of its position (starting from 0 on the right) and add the results.
Example: $ 1120_{(3)} $ becomes $ 1 \times 3^3 + 1 \times 3^2 + 2 \times 3^1 + 0 \times 3^0 = 42 $
dCode retains ownership of the "Ternary Code (Base 3)" source code. Any algorithm for the "Ternary Code (Base 3)" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Ternary Code (Base 3)" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Ternary Code (Base 3)" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Ternary Code (Base 3)" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Ternary Code (Base 3) on dCode.fr [online website], retrieved on 2026-03-25,