Number Base

Math

Convert between binary, octal, decimal, hex, and custom bases (2-36).

Import

Import
import { numberBase } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
baseConvertvalue: string, fromBase: number, toBase: numberstringConvert between any bases (2-36)
toBinaryvalue: string | numberstringConvert decimal to binary
toOctalvalue: string | numberstringConvert decimal to octal
toHexvalue: string | numberstringConvert decimal to hexadecimal
fromBinaryvalue: stringstringConvert binary to decimal
fromHexvalue: stringstringConvert hex to decimal
convertAllBasesvalue: string | number, fromBase?: numberRecord<string, string>Convert to all common bases

Examples

Basic Conversion
import { toHex, toBinary } from 'toolmetry';

const hex = toHex(255);
// "FF"

const binary = toBinary(10);
// "1010"
Custom Base Conversion
import { baseConvert } from 'toolmetry';

const result = baseConvert('FF', 16, 10);
// "255"
Convert to All Bases
import { convertAllBases } from 'toolmetry';

const all = convertAllBases(255);
// { decimal: "255", binary: "11111111", octal: "377", hex: "FF" }

Try It Live