base-conversion-from-dec

2.2.0 • Public • Published

base-conversion-from-dec

Build Status Coverage Status Code Climate

Auto-curried converter to any base with arbitrary precision support and customisable symbols.

For the opposite behaviour, see base-conversion-to-dec. For any to any base conversions, see base-conversion.

Install

npm i base-conversion-from-dec

Basic usage

var bc = require('base-conversion-from-dec');
var toBin = bc(2);
 
hexToBin('10'); //=> '1010'
hexToBin(30); //=> '11110'

See spec.

Custom symbols

For any bases above 62, custom symbols are required. See tests for working examples.

var bc = require('base-conversion-from-dec');
 
bc.symbols('⓿①②③④⑤⑥⑦⑧⑨ⒶⒷ', 12, '⑦③'); //=> '⑥①'

Arbitrary precision

var bc = require('base-conversion-from-dec');
var Big = require('arbitrary-precision')(require('bigjs-adapter'));
var toBigFactory = require('to-decimal-arbitrary-precision');
 
var d = toBigFactory(Big);
 
// avoid large numbers to go into exponential notation (adapter dependent)
Big.Impl.E_POS = 50;
 
bc.big(d, 9, '5678364565345634563456346757364563534534645745');
//=> '802531310452364303450750087576673257456135727727'

Full raw version

var bc = require('base-conversion-from-dec');
var Big = require('arbitrary-precision')(require('bigjs-adapter'));
var toBigFactory = require('to-decimal-arbitrary-precision');
 
var d = toBigFactory(Big);
 
// avoid large numbers to go into exponential notation (adapter dependent)
Big.Impl.E_POS = 50;
 
bc.raw(d, '01234#6789', 9, '#678364#6#34#634#634#63467#7364#63#34#3464#74#');
//=> '802#313104#23643034#07#0087#766732#74#613#727727'

Defaults

The default symbols and big implementation are exposed as follows:

bc.defaultSymbols; //=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
bc.defaultB; //=> default arbitrary precision implementation (div & mod)

Package Sidebar

Install

npm i base-conversion-from-dec

Weekly Downloads

35

Version

2.2.0

License

MIT

Last publish

Collaborators

  • javiercejudo