BinDec JavaScript API
A tiny (3 KB) number-base conversion library for your own apps — any base 2–36, arbitrary precision, zero dependencies. Free for any use.
Install
Add one script tag — BinDec becomes a global:
<script src="https://binary-to-decimal-28z.pages.dev/bindec.js"></script>
It is a UMD module, so it also works with AMD loaders and in Node.js via require("bindec.js").
Quick start
BinDec.convert("ff", 16, 10); // → "255"
BinDec.convert("1010", 2, 10); // → "10"
BinDec.convert("100", 10, 36); // → "2s"
BinDec.convert("0xFF", 16, 2); // → "11111111"
Function reference
| Function | Description |
|---|---|
BinDec.convert(value, fromBase, toBase) | Convert value from fromBase to toBase (2–36). Returns a string (uppercase for the result digits). Throws on invalid input. |
BinDec.toDecimal(value, fromBase) | Parse value in fromBase and return a BigInt decimal. Throws on invalid input. |
BinDec.fromDecimal(value, toBase) | Convert a BigInt, number or decimal string to a toBase string (lowercase digits). |
BinDec.isValid(value, base) | Return true if value is a valid number in base. |
BinDec.normalize(value, base) | Helper: return { digits, neg } with prefixes and separators stripped. |
Parsing rules
- Bases: any integer 2–36. Digits
0–9thenA–Z(case-insensitive) for values 10–35. - Prefixes
0b,0o,0xare accepted for bases 2, 8 and 16. - Spaces, commas, underscores and dashes are ignored; a leading
-means negative. - Precision is exact — the library uses
BigIntthroughout, so 100-digit inputs are fine.
Try it live
BinDec.convert(...)
This console runs the real library loaded from the CDN tag above.
Frequently asked questions
Is the BinDec API free to use?
Yes — the library is free for any use, including commercial projects. Attribution is appreciated but not required.
Which number bases are supported?
Any base from 2 to 36. Digits are 0–9 plus letters A–Z (case-insensitive) for values 10–35.
How large can the numbers be?
There is no practical limit — the library uses BigInt arbitrary-precision arithmetic, so inputs hundreds of digits long convert exactly.
Does it handle prefixes like 0x and messy input?
Yes — 0x, 0b and 0o prefixes are recognized for the matching base, and spaces, commas, underscores and dashes are ignored. Invalid digits throw a descriptive error.
Does it work in Node.js?
Yes — it is a UMD module, so it works as a browser global (window.BinDec), with AMD loaders, and via require('bindec.js') in Node.js.