Giter Club home page Giter Club logo

any-to-any's Introduction

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.

Note about the new experimental convert:

We export a new experimental method experimentalConvert maybe to solve problem of large numbers between hexa and decimal and up to 64 base.

You can use it with careful until we release the next major release (v5.0.0).

Please, if you find any problem or you have suggestion to improve the experiance with this module feel free to open an issue.

License


MIT © Imed Jaberi

any-to-any's People

Contributors

3imed-jaberi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

any-to-any's Issues

please check the input value

import {convert} from "any-to-any";
const invalid_binary = '23942394234';// binary should be between 0,1

console.log(convert(invalid_binary,2,16)) // return   1AA2

it should be return an error, because the input is an invalid binary

2 Bugs !!!!!

------------ Bug 1 ------------
convert(0, 10, 36) returns null, it should be 0

------------ Bug 2 ------------
change:
const { Convert } = require('any-to-any')
to:
const { convert } = require('any-to-any')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.