Skip to content

A number system conversion library. Supports binary, octal, decimal and hexadecimal.

License

Notifications You must be signed in to change notification settings

patzj/number-system

Repository files navigation

number-system NPM version Build Status

A number system conversion library. Supports binary, octal, decimal and hexadecimal.

Installation

$ npm install --save number-system

Usage

Creating Instance

var NumberSystem = require('number-system');

// Creates a NumberSystem object that converts from decimal to target base
var ns = new NumberSystem(10);

Supported Bases

  • 2 - Binary
  • 8 - Octal
  • 10 - Decimal
  • 16 - Hexadecimal

Basic Conversion

// Returns '1100011'
ns.bin(99);

// Returns '1100011'
ns.bin('99');

Available Conversion Methods

Method Description Parameter
bin Converts argument to binary Number or String value
oct Converts argument to octal Number or String value
dec Converts argument to decimal Number or String value
hex Converts argument to hexadecimal Number or String value

Note: Use String arguments when converting hexadecimal values with alpha characters (e.g. 0xff).

Changing Base

// Returns 10
ns.base;

// Changes the original base to hexadecimal
ns.base = 16

// Returns 16
ns.base;

// Returns '0143'
ns.oct(63);

// Returns '99'
ns.dec('0x63');

License

MIT

About

A number system conversion library. Supports binary, octal, decimal and hexadecimal.

Resources

License

Stars

Watchers

Forks

Packages

No packages published