mixed-radix
v1.0.0
Published
Mixed Radix
Downloads
2,830
Readme
Mixed Radix
A small library that encode and decode using mixed radix.
Install
npm install --save mixed-radix
Usage
mrDecode([2, 3], 5); // [1, 2]
mrEncode([2, 3], [1, 2]); // 5
mrDecode([3, 3, 2], 7); // [1, 0, 1]
mrEncode([3, 3, 2], [1, 0, 1]); // 7
mrDecode([24, 24, 60], 3661); // [1, 1, 1]
mrEncode([24, 60, 60], [1, 1, 1])); // 3661
API
mrEncode(bases, ns)
Encodes using mixed radix.
- bases:
number[]
Mixed bases, must be integers. - ns:
number[]
Values to encode, must be an array of integer with the same length as bases.
return: number
Encoded values.
mrDecode(bases, n)
Decodes mixed radix.
- bases:
number[]
Mixed bases, must be an array integers. - n:
number[]
Values to decode, must be an integer.
return: number[]
Decoded values.
License
MIT