Number base converter

Convert integers between binary, octal, decimal, hex, and bases 2-36. Uses BigInt for arbitrary precision.

Convert integers between binary, octal, decimal, hexadecimal, and custom bases 2-36 in your browser. Digits are 0-9a-z (case-insensitive); each digit must be less than the from-base. Parsing uses Horner's method on BigInt: value * radix + digit. For example, hex ff to decimal is 255 (case-insensitive: FF also produces 255). Output uses BigInt.prototype.toString(radix). Not Number.parseInt, not two's complement, and not a float dump. For cryptographic hashes, see /hash-generator/. Nothing is uploaded.

From base

To base

Input
Output

How it works

  1. Enter an integer, pick From and To bases (Binary 2, Octal 8, Decimal 10, Hex 16, or Custom 2–36), and click Convert. For example, hex ff to decimal produces 255. Copy writes the output string. Nothing is uploaded.
  2. Parse trims the input, accepts an optional leading -, then reads at most 256 digits from 0-9a-z (letters via toLowerCase()). Each digit value must be less than the from-base. The integer is Horner's method on BigInt: value = value * radix + digit. Hex ff is 0 × 16 + 15 = 15, then 15 × 16 + 15 = 255. FF converts to that same 255. 0xff fails on x (it is not a hex digit), not because a prefix is stripped. This is not Number.parseInt(that stops at the first invalid character and uses IEEE-754).
  3. Output is BigInt.prototype.toString(radix) (ECMA-262, lowercase). Decimal 255 to hex writes ff. Uppercase reformats those letters and does not change the value (255 to hex with Uppercase is FF). Leading zeros are dropped. Zero is 0. A leading minus is a mathematical sign, not two's complement.
  4. Rejected: 0x / 0b / 0o prefixes, underscores, interior spaces, fractions, scientific notation, bases outside 2-36, fixed-width two's complement, IEEE-754 dumps, and custom alphabets (not Base58 / Base62 / Base64). For cryptographic hashes (SHA-256 / SHA-1 / MD5), see /hash-generator/.

Positional BigInt vs Number.parseInt

This page folds each digit with Horner's method on BigInt (value * radix + digit) and rejects a character that is not a digit in the from-base. Number.parseInt is an IEEE-754 Number that stops at the first invalid digit. Node's parseInt is the same function; CPython int(s, radix) rejects like this page. For the longer comparison, see Positional BigInt vs Number.parseInt.

AspectThis page (BigInt)Number.parseInt
AlgorithmHorner on BigIntPrefix scan to an IEEE-754 Number
PrecisionExact integers, at most 256 digitsExact through 2^53 − 1 (9007199254740991)
Invalid digitRejects; 1012 in base 2 throwsparseInt("1012", 2) is 5
Prefixes0x / 0b / 0o rejected (x is not a hex digit)parseInt("0x10", 16) is 16; 0b / 0o are not special
Past 53 bitsKeeps 9007199254740993parseInt("9007199254740993", 10) is 9007199254740992
OutputBigInt.prototype.toString(radix) (lowercase 0-9a-z)A Number, then toString

Hex ff to decimal is 255 on both paths. parseInt("fg", 16) is 15; this page rejects g. Hex 20000000000001 is 2^53 + 1 — Horner keeps the odd integer; parseInt("20000000000001", 16) is 9007199254740992. This is not two's complement and not a custom alphabet. Encoding UTF-8 as RFC 4648 §8 hex belongs on Base16, not this integer converter.

Convert number bases in Python and Node

The snippets below convert the hex integer this page documents in how-it-works — ff — to decimal 255, then back to lowercase hex. Node uses BigInt.prototype.toString(radix) for output, the same ECMA-262 method as this page. Python int is arbitrary-precision like BigInt, not an IEEE-754 Number. Neither snippet is two's complement, Base58, or a float dump. For why this page does not call Number.parseInt, see Positional BigInt vs Number.parseInt.

Node.js with BigInt and toString

BigInt parses integer literals only — hex needs a 0x prefix, binary 0b, octal 0o. This page rejects those prefixes (x is not a hex digit) and reads bare ff with Horner's method. Output toString(16) matches this page (lowercase, no prefix):

const value = BigInt('0xff');
const decimal = value.toString(10);
// "255"

const hex = value.toString(16);
// "ff"

const hexUpper = value.toString(16).toUpperCase();
// "FF"

Python with int and format

CPython int(s, 16) accepts bare ff or 0xff. This page accepts only the bare form. format(n, 'x') writes lowercase hex without a prefix, matching this page. hex(255) is '0xff' — a prefix this page does not add. Invalid digits raise ValueError:

value = int('ff', 16)
decimal = str(value)
# '255'

hex_lower = format(value, 'x')
# 'ff'

hex_upper = format(value, 'X')
# 'FF'

Number.parseInt('ff', 16) is also 255, but it is an IEEE-754 Number (exact integers only through 253 − 1) and stops at the first invalid character — parseInt('fg', 16) is 15. This page and CPython int('fg', 16) reject g. int(s, radix) parses any base 2–36; format only has b / o / x. For other radices, Node toString(radix) matches this page's lowercase 0-9a-z output. BigInt('ff') throws SyntaxError.

Convert number bases in the shell

POSIX bc is an arbitrary-precision calculator. Its ibase / obase registers set the input and output radix. POSIX.1-2024 limits ibase to 2–16; this page accepts 2–36. Hex digits in bc are uppercase A–F — lowercase letters are names. GNU bc 1.07.1 printed 0 for ibase=16; ff (unset f is 0). This page maps ff and FF to 255. obase=16 writes uppercase FF; this page's default hex is lowercase ff.

GNU bc (Linux)

GNU bc 1.07 follows the uppercase hex alphabet POSIX names. Set ibase or obase while those registers are still decimal (the default is 10). Single-digit A–F keep their values 10–15 even after ibase changes:

echo 'ibase=16; FF' | bc
# 255

echo 'obase=16; 255' | bc
# FF

echo 'ibase=16; ff' | bc
# 0

printf (GNU coreutils / POSIX)

GNU coreutils 9.4 and dash treat 0xff as a C-style integer constant. printf '%x' writes lowercase hex; %X writes uppercase. This page rejects 0xff because x is not a hex digit. GNU printf rejects bare ff as an invalid number; this page maps that spelling to 255:

printf '%d\n' 0xff
# 255

printf '%x\n' 255
# ff

printf '%X\n' 255
# FF

Bash $((16#ff)) is 255 (bash-only). POSIX dash $((0xff)) is 255; $((16#ff)) is a syntax error. GNU bc 1.07.1 accepted ibase=36; Z as 35 — a GNU extension; POSIX ibase max is 16. obase=36; 35 wrote a space-padded two-digit decimal 35, not this page's z. Single-digit G with ibase=16 was 16 in GNU bc; multi-digit FG became 255 because GNU bc rewrites a digit ≥ ibase as ibase−1. This page rejects G in hex. ibase=16; 0xFF is a syntax error in GNU bc 1.07.1. For Python int and Node BigInt (bases 2–36), see the section above.

FAQ

Does this converter upload anything?
No. Convert and copy run in your browser. The page does not send the number to a server.
Which bases and digits are accepted?
From and to bases are integers 2-36. Digits are 0-9 then a-z (case-insensitive). A digit value must be less than the from-base, so 2 is invalid in binary and G is invalid in hex. Hex ff to decimal produces 255. FF produces the same 255. 0xff is rejected because x is not a hex digit. An optional leading minus is a mathematical sign, not two's complement. Prefixes (0x, 0b, 0o), underscores, spaces, fractions, and scientific notation are rejected.
How is the number converted?
The input is trimmed, then each digit is folded with Horner's method on BigInt: value = value * radix + digit. Hex ff is 0 × 16 + 15 = 15, then 15 × 16 + 15 = 255. Output is BigInt.prototype.toString(radix) (ECMA-262, lowercase 0-9a-z). Decimal 255 to hex produces ff; Uppercase returns FF. This is not Number.parseInt, which stops at the first invalid character and is an IEEE-754 Number (exact integers only through 2^53 - 1).
Is this two's complement, Base58, or a float converter?
No. There is no bit width, no two's complement wrap, no IEEE-754 binary32/binary64 dump, and no custom alphabet (not Base58, Base62, or Base64). Zero is 0. Leading zeros are accepted on input and dropped on output. At most 256 digits after the optional minus. Encoding UTF-8 text as RFC 4648 hex (foobar becomes 666F6F626172) is at /base16/, not this integer converter. For cryptographic hashes, see /hash-generator/.

Related