number-system
A number system conversion library. Supports binary, octal, decimal and hexadecimal.
Installation
$ npm install --save number-system
Usage
Creating Instance
var NumberSystem = ; // Creates a NumberSystem object that converts from decimal to target basevar ns = 10;
Supported Bases
- 2 - Binary
- 8 - Octal
- 10 - Decimal
- 16 - Hexadecimal
Basic Conversion
// Returns '1100011'ns; // Returns '1100011'ns;
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 10nsbase; // Changes the original base to hexadecimalnsbase = 16 // Returns 16nsbase; // Returns '0143'ns; // Returns '99'ns;
License
MIT