https://github.com/javiercejudo/base-conversion-to-dec
Auto-curried converter from any base with arbitrary precision support and customisable symbols
https://github.com/javiercejudo/base-conversion-to-dec
Last synced: about 2 months ago
JSON representation
Auto-curried converter from any base with arbitrary precision support and customisable symbols
- Host: GitHub
- URL: https://github.com/javiercejudo/base-conversion-to-dec
- Owner: javiercejudo
- License: mit
- Created: 2016-02-20T12:59:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-02T12:47:29.000Z (over 9 years ago)
- Last Synced: 2025-03-22T09:16:37.078Z (3 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/base-conversion-to-dec
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# base-conversion-to-dec
[](https://travis-ci.org/javiercejudo/base-conversion-to-dec)
[](https://coveralls.io/r/javiercejudo/base-conversion-to-dec?branch=master)
[](https://codeclimate.com/github/javiercejudo/base-conversion-to-dec)Auto-curried converter from any base with arbitrary precision support and customisable symbols.
For the opposite behaviour, see [base-conversion-from-dec](https://github.com/javiercejudo/base-conversion-from-dec).
For any to any base conversions, see [base-conversion](https://github.com/javiercejudo/base-conversion).## Install
npm i base-conversion-to-dec
## Basic usage
```js
var bc = require('base-conversion-to-dec');
var hexToBin = bc(16, 2);hexToBin('A'); //=> '1010'
hexToBin('1E'); //=> '11110'
```See [spec](test/spec.js).
## Fractional support (including bases)
```js
bc(9, '11.08'); //=> '10.098765432098766'
```See in [Wolfram|Alpha](https://www.wolframalpha.com/input/?i=convert+11.08_9+to+base10).
```js
bc(3.145, '100.01'); //=> '9.992126756390263'
```See in [Wolfram|Alpha](https://www.wolframalpha.com/input/?i=convert+100.01+from+base+3.145+to+base10).
## Custom symbols
For any bases above 62, custom symbols are required.
See [tests](test/bigint-base-converter.js) for working examples.```js
bc.symbols('⓿①②③④⑤⑥⑦⑧⑨ⒶⒷ', 12, '⑥①'); //=> '⑦③'
```## Arbitrary precision
```js
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, '802531310452364303450750087576673257456135727727');
//=> '5678364565345634563456346757364563534534645745'
```## Full raw version
```js
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, '802#313104#23643034#07#0087#766732#74#613#727727');
//=> '#678364#6#34#634#634#63467#7364#63#34#3464#74#'
```## Defaults
The default symbols and big implementation are exposed as follows:
```js
bc.defaultSymbols; //=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
bc.defaultB; //=> default arbitrary precision implementation (plus, times & pow)
```