Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-conversion-to-dec

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-conversion-to-dec

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

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

base-conversion-to-dec

Build Status Coverage Status Code Climate

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

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

Install

npm i base-conversion-to-dec

Basic usage

var bc = require('base-conversion-to-dec');
var hexToBin = bc(16, 2);

hexToBin('A'); //=> '1010'
hexToBin('1E'); //=> '11110'

See spec.

Fractional support (including bases)

bc(9, '11.08'); //=> '10.098765432098766'

See in wolfram|Alpha.

bc(3.145, '100.01'); //=> '9.992126756390263'

See in wolfram|Alpha.

Custom symbols

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

bc.symbols('⓿①②③④⑤⑥⑦⑧⑨ⒶⒷ', 12, '⑥①'); //=> '⑦③'

Arbitrary precision

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

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:

bc.defaultSymbols; //=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
bc.defaultB; //=> default arbitrary precision implementation (plus, times & pow)

Keywords

FAQs

Package last updated on 28 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc