any-to-any

convert numbers between bases (any base to any base) 🔀 ..

Usage no npm install needed!

<script type="module">
  import anyToAny from 'https://cdn.skypack.dev/any-to-any';
</script>

README

ANY-TO-ANY - converts numbers between bases ; binary , decimal , octal , hexadecimal and muche more ..


imed-jaberi

Build Status    Coverage Status    NPM version    License    Top Language    Code Size    Code of Conduct    PRs Welcome   

The purpose of this module is to convert numbers from any base to other base you want.

Limitation

This module can convert only the integers numbers between base 2 & base 36. Soon, it will be possible to convert real numbers [wip].

Installation

# npm ..
$ npm install any-to-any
# yarn ..
$ yarn add any-to-any

Usage

This is a practical example of how to use.

// const convert = require('any-to-any')
const { convert } = require("any-to-any");

const inputNumber = "1110111"; // 119 in decimal
const inputBase = 2;
const outputBase = 8;

const result = convert(inputNumber, inputBase, outputBase);
console.log(result);
//  167

// NOTE: in case the input number is consists of numbers only,
// you can enter the number to the function in number type ..
const inputNumber = 1110111; // 119 in decimal
const inputBase = 2;
const outputBase = 8;
const result = convert(inputNumber, inputBase, outputBase);
console.log(result);
//  167

Also, we have 2 exported methods to convert a value from any base to Decimal (base 10) called anyBaseToDecimal and the reverse one from Decimal to any base named decimalToAnyBase.

NOTE: There are a set of suggested examples that have been tested that you can follow here.

License


MIT © Imed Jaberi