Convert between binary, octal, decimal, hex, and custom bases (2-36).
import { numberBase } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
baseConvert | value: string, fromBase: number, toBase: number | string | Convert between any bases (2-36) |
toBinary | value: string | number | string | Convert decimal to binary |
toOctal | value: string | number | string | Convert decimal to octal |
toHex | value: string | number | string | Convert decimal to hexadecimal |
fromBinary | value: string | string | Convert binary to decimal |
fromHex | value: string | string | Convert hex to decimal |
convertAllBases | value: string | number, fromBase?: number | Record<string, string> | Convert to all common bases |
import { toHex, toBinary } from 'toolmetry';
const hex = toHex(255);
// "FF"
const binary = toBinary(10);
// "1010"import { baseConvert } from 'toolmetry';
const result = baseConvert('FF', 16, 10);
// "255"import { convertAllBases } from 'toolmetry';
const all = convertAllBases(255);
// { decimal: "255", binary: "11111111", octal: "377", hex: "FF" }