Skip to main content
UtilitiesFree · no sign-up

Number Base Converter

Binary, octal, decimal and hex side by side, plus any base from 2 to 36.

Updated

Spaces, underscores and commas are ignored, so you can paste a grouped value straight in. A leading minus sign is kept.

Any base from 2 to 36. Above base 10 the digits continue into the letters, so base 36 runs 0 to 9 then a to z.

The same value, five ways

Binary (base 2)

1111 1111

Octal (base 8)

377

Decimal (base 10)

255

Hexadecimal (base 16)

FF

Custom (base 36)

73

Bits
8
Bytes to hold it
1
Hex digits
2

One hexadecimal digit is exactly four binary digits, which is why the binary column groups in fours and lines up with the hex column digit for digit. Octal groups in threes for the same reason.

In short

Why does a 64-bit hex value need BigInt to convert correctly?

Because a JavaScript number is an IEEE 754 double with 53 bits of significand, and 0xFFFFFFFFFFFFFFFF needs 64. Sent through a double it returns 18446744073709551616, one more than the true 18446744073709551615, and nothing warns you. This converter uses BigInt throughout, so all 20 digits survive exactly.

The panel flags the moment a value passes 9007199254740991, the largest integer an ordinary JavaScript number can represent without rounding.

How to use the number base converter

Paste a value, tell the tool which base it is written in, and every other base appears at once. The conversion is exact at any size, because the arithmetic runs on BigInt rather than on ordinary numbers, and there is a copy button on each row so you can take just the form you need.

The reason all four bases appear together is that base questions are almost always comparisons. You are checking whether 0xFF and 255 are the same value, or which bits a mask actually sets, or whether a permission octet matches the binary you expected. Showing one answer at a time makes you do that comparison in your head.

11111111

Binary

eight bits, all set

FF

Hexadecimal

two digits, one byte

255

Decimal

the value the tool opens on

Hexadecimal earns its place because 16 is 2 to the power of 4, so one hex digit is exactly four binary digits and the two notations line up column for column. FF is 1111 1111, and B4 is 1011 0100. Nothing has to be calculated, only looked up, which is why hex is the shorthand for binary everywhere.

Octal works the same way one rung down, since 8 is 2 to the power of 3 and one octal digit is exactly three bits. That is why Unix file permissions are octal: three bits for read, write and execute is one digit per user class, so 755 is 111 101 101 and reads straight off the number.

The same care applies to the input side. parseInt stops at the first character it does not recognise and returns whatever it managed to read, so parsing 12G4 as hexadecimal gives 18 rather than an error. This tool names the offending character instead, because a value with a typo in it is a question, not a number.

Do

  • Group binary in nibbles so each group of four lines up with one hex digit.
  • Use hex for bit masks and octal for Unix permission bits.
  • Check the bit count before storing a value in a fixed width field.
  • Prefix hex with 0x and binary with 0b in code so the base is never ambiguous.
  • Reach for base 32 or base 36 when you want a short human-typeable identifier.

Don't

  • Convert a value over 53 bits through an ordinary floating point number.
  • Assume a bare string of digits is decimal when it came out of a config file.
  • Read a leading zero as decoration, since some languages parse it as octal.
  • Mix uppercase and lowercase hex within one file or one column.
  • Confuse a count of bits with a count of bytes when sizing a field.

Values worth recognising across the four common bases, with the bit width each one occupies.

BinaryOctalDecimalHexadecimalBits
10101210A4
100002016105
11111111771277F7
10000000200128808
11111111377255FF8
1111101000175010003E810
100000000002000102440011
1000000000000100004096100013
111111111111111117777765535FFFF16
10000000000000000200000655361000017
Every row was produced by the converter above. Paste any decimal value from the third column back in to reproduce its row exactly.

Why every colour on the web is written in hex

A screen colour is three independent channels, red, green and blue, and each one is stored in a single byte with 256 possible levels. One byte is exactly two hex digits, so three bytes is exactly six, and that is the whole explanation for the six-character colour codes CSS has used since the beginning.

Taking #FF8800 apart
FF, the red channel
255, fully on
88, the green channel
136, a little over half
00, the blue channel
0, fully off
The whole value as one number
16746496 decimal, 24 bits

Each pair is one byte, which is why the six-digit form splits so cleanly and the decimal form does not split at all.

Try that split in decimal and the reason becomes obvious. The same colour is 16746496, and there is no way to see the three channels in it without dividing twice. In hex you read the pairs straight off the string, which is why designers and developers both learned to think in FF and 88 rather than 255 and 136.

The three-digit shorthand follows from the same arithmetic. CSS expands #F80 to #FF8800 by doubling each digit, so it can only express the 16 levels per channel where both digits match. It is a convenience for round numbers rather than a compressed format, and it cannot describe 136 at all.

Alpha is simply a fourth byte on the end, so #FF8800CC adds an opacity of 204 out of 255. The ordering is the thing to watch, because some platforms and file formats put alpha first instead, and a colour that comes out inexplicably transparent is usually an ARGB value being read as RGBA.

The 1000 against 1024 problem, in one paragraph

Memory is addressed in powers of two, so 1024 rather than 1000 is the natural step, and early computing borrowed the metric kilo prefix for it anyway. That borrowing is the entire source of the confusion, because a kilobyte then meant 1024 bytes to a programmer and 1000 bytes to everyone who had ever used the prefix before.

The prefixes kibi, mebi and gibi denote the binary multiples 1024, 1024 squared and 1024 cubed, distinguishing them from the decimal SI prefixes kilo, mega and giga.
IEC 80000-13:2008, Quantities and units, Part 13: Information science and technology

The standard fix has existed since 1998 and is now IEC 80000-13: kibibyte, mebibyte and gibibyte for the binary multiples, leaving kilo, mega and giga to mean exactly what they mean everywhere else in science. Adoption is uneven, which is why a drive sold as 500 GB shows up as roughly 465 GiB once formatted.

The base arithmetic behind it is visible in this tool. 1024 is 400 in hex and takes 11 bits, 4096 is 1000 in hex and takes 13, and 65536 is 10000 in hex and takes 17. Every one of them is a clean round number in hex and an awkward one in decimal, which is the whole reason the binary sizes stuck.

Converting storage sizes properly

The decimal against binary prefix mess deserves its own page rather than a footnote here. The megabyte to gigabyte converter handles both conventions and shows where the missing space went.

Open the MB to GB converter

The formula, worked line by line

A positional number system is one rule applied repeatedly: each digit is multiplied by the base raised to the power of its position, counting from zero on the right, and the results are added. Decimal is that rule with a base of 10, and every other base is the same rule with a different multiplier.

Conversion between two bases is therefore two passes rather than one clever step. Read the input into an exact magnitude using the source base, then write that magnitude out by repeatedly dividing by the target base and collecting the remainders. Nothing about the value changes in between, only its spelling.

value = sum of digit[i] x base^i, counting positions from zero on the right
to write in a base: divide repeatedly, collect remainders, read them bottom to top
digits above 9 continue into letters, so base 36 runs 0 to 9 then a to z
one hex digit = 4 bits because 16 = 2^4
one octal digit = 3 bits because 8 = 2^3
One hex digit is exactly four bitsHexadecimal B4 is binary 1011 0100 and decimal 180. Each hex digit maps to its own group of 4 bits, called a nibble, because 16 is 2 to the power of 4. Decimal has no such alignment, which is why converting hex to binary is a lookup and converting decimal to binary is arithmetic.16 = 2⁴, SO 1 HEX DIGIT = 4 BITSB18041211408140201B4 hex = 180 decimaldecimal never lines up like this, because 10 is not a power of two0xB4binary10110100octal264base 3650decimal180
One hex digit over the four bits it stands for, which is why hex and binary line up.
Reading B4 as hexadecimal
B in position 1
11 x 16 = 176
4 in position 0
4 x 1 = 4
As binary nibbles
1011 0100
As octal
264
Decimal
180

The binary line is the one worth staring at. B is 1011 and 4 is 0100, so the two nibbles simply sit next to each other with nothing carried between them.

That nibble alignment only works because 16 is a power of two. Decimal is not, so there is no group of bits that corresponds to one decimal digit, and converting between decimal and binary genuinely requires arithmetic rather than a lookup. It is the reason hex exists as a notation at all.

The exactness is the other half of the story. IEEE 754 double precision, the format an ordinary JavaScript number uses, carries a 53-bit significand, so every integer up to 9007199254740991 is exact and beyond that the gaps start. The first casualty is 2 to the power of 53 plus 1, which cannot be represented and silently becomes 2 to the power of 53.

Base 36 is where the digit alphabet runs out, since 10 numerals plus 26 letters is 36 symbols and there is no agreed thirty-seventh. That is also why base 36 shows up in short identifiers: it packs the most value into each character that a case-insensitive alphanumeric string can carry.

Questions people ask

Sources

Where the constants and formulas on this page come from. Each line names the figure it backs.

  1. The binary prefixes kibi, mebi and gibi denote 2 to the 10th, 20th and 30th, and are deliberately distinct from the decimal kilo, mega and giga.

    Prefixes for binary multiplesNIST

  2. Each hex pair in a six-digit colour is one channel, and the three-digit shorthand expands by duplicating each digit.

    CSS Color Module Level 4W3C