FileGizmo Developer tools

Convert a number between bases

Binary, octal, decimal, hex and every base up to 36, converted exactly. Long identifiers keep every digit, which the usual one-line approach does not manage.

Never uploadedYour file stays on this device

Simple by design

Number base converter in three steps

Binary to decimal, decimal to hex, hex to binary. It is a job with an obvious answer that most implementations get slightly wrong in a way that matters exactly when the number is important.

The precision problem

The one-line version of this tool is parseInt(value, from).toString(to). It is correct for small numbers, which is why it survives in so many places.

It stops being correct at around sixteen digits, because the intermediate value is a double and a double cannot hold an integer past 2^53 exactly. Convert a 64-bit identifier through it and you get a number back that looks entirely plausible and has different digits from the one you put in. There is no error and no warning; the value is simply not the value any more.

This is exactly the range that matters. Snowflake identifiers, database primary keys, hardware addresses, IMEIs and file offsets all live above 2^53, and they are the numbers people convert bases for. A tool that quietly rounds them is worse than no tool, because the answer looks right.

So the conversion here uses arbitrary-precision integers throughout. There is no floating-point step and no upper limit beyond memory. A three hundred digit number converts exactly.

Whole numbers only

Fractions are not supported, and that is a decision rather than an omission.

A fraction that terminates in one base frequently does not terminate in another. One tenth is exact in decimal and infinitely repeating in binary, which is the source of most surprising arithmetic in every programming language. Converting fractional digits means choosing how many to emit and rounding the rest, and silently rounding a number is the precise failure this tool is built to avoid.

Bases and their digits

Any base from 2 to 36 works, in either direction. The limit is not arbitrary: base 36 is the last one that can be written with the ten digits and the twenty-six letters of the alphabet, and past it there is no agreed set of symbols.

The common ones have their own reasons. Base 2 is what the hardware does. Base 8 survives in file permissions because three bits fit one digit. Base 16 is the readable form of bytes, two digits each. Base 36 turns up in short identifiers and URL slugs because it packs the most information into characters that survive a copy and paste.

Letters are case insensitive on the way in and lowercase on the way out unless you ask otherwise. One number per line, so a column of values can be converted together, and a line that is not valid in the base you named is reported rather than skipped.

  1. 1

    Paste one number per line

  2. 2

    Set the base you are converting from and the base you want

  3. 3

    Press Convert the numbers

Good to know

Frequently asked questions

Does it handle numbers too large for JavaScript?

Yes, and this is the reason the tool exists rather than a one-line answer. Conversion uses arbitrary-precision integers, so a 64-bit identifier keeps every digit. The usual parseInt approach stops being exact past about sixteen digits and changes the number without saying so.

Which bases are supported?

Any base from 2 to 36 in either direction. Base 36 is the last one that can be spelled with the ten digits and the twenty-six letters.

Can it convert fractions?

No. Whole numbers only. A fraction in one base often has no exact representation in another, and rounding a number silently is the thing this tool is built to avoid.

Are negative numbers supported?

Yes. A leading minus sign is kept and the digits are converted as normal. This is a sign and magnitude conversion, not a two's complement one.