A number system conversion library. Supports binary, octal, decimal and hexadecimal.
$ npm install --save number-systemvar NumberSystem = require('number-system');
// Creates a NumberSystem object that converts from decimal to target base
var ns = new NumberSystem(10);- 2 - Binary
- 8 - Octal
- 10 - Decimal
- 16 - Hexadecimal
// Returns '1100011'
ns.bin(99);
// Returns '1100011'
ns.bin('99');| 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).
// 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');MIT