https://github.com/semibran/radix
Convert whole numbers to any base
https://github.com/semibran/radix
base convert numbers radix
Last synced: about 1 year ago
JSON representation
Convert whole numbers to any base
- Host: GitHub
- URL: https://github.com/semibran/radix
- Owner: semibran
- License: mit
- Created: 2017-07-27T03:51:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-27T04:03:42.000Z (almost 9 years ago)
- Last Synced: 2025-02-12T18:59:21.179Z (over 1 year ago)
- Topics: base, convert, numbers, radix
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# radix
> Convert whole numbers to any base
## usage
### `encode(digits, number) -> string`
Encodes `number` into a `string` using `digits`.
```js
> var binary = ["0", "1"]
> encode(binary, 255)
"11111111"
```
### `decode(digits, string) -> number`
Decodes `string` back into a `number` using `digits`.
```js
> var hex = "0123456789ABCDEF"
> decode(hex, "DEADBEEF")
3735928559
```
Returns `NaN` if `string` contains a character not included in `digits`.
```js
> decode(hex, "GOTEM")
NaN
```
## license
[MIT](https://opensource.org/licenses/MIT) © [Brandon Semilla](https://git.io/semibran)