1.0.2 • Published 4 years ago

number-system v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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

MethodDescriptionParameter
binConverts argument to binaryNumber or String value
octConverts argument to octalNumber or String value
decConverts argument to decimalNumber or String value
hexConverts argument to hexadecimalNumber 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