/balanced-ternary

balanced ternary base 3 radix conversion

Primary LanguageJavaScriptMIT LicenseMIT

balanced-ternary

Convert balanced ternary strings to/from signed integers

Build Status npm version

Usage:

var bts2n = require('balanced-ternary').bts2n;
var n2bts = require('balanced-ternary').n2bts;

bts2n('10i');   // 8
n2bts(8);       // '10i'

bts2n(s) converts from balanced ternary string to signed integer, n2bts(n) converts from signed integer to balanced ternary string.

Digits 1, 0, and i correspond to +1, 0, and -1.

Reference: Balanced ternary on Wikipedia