Binary, Hex and Decimal: How to Convert Between Number Bases

Oct 21, 2026 · 2 min read · Developer

We count in tens because we have ten fingers. Computers count in twos because a switch is either on or off. Programmers also use hexadecimal, which counts in sixteens. The same number can be written in all of them.

The four common bases

One number, many ways

The number 255 is 11111111 in binary and FF in hex. Notice that hex is much shorter. One hex digit stands for exactly four binary digits, which is why developers like it.

Where you meet hex

Converting decimal to binary by hand

Keep dividing the number by 2 and write down the remainders. For 13: 13 divided by 2 is 6 remainder 1, then 3 remainder 0, then 1 remainder 1, then 0 remainder 1. Read the remainders from bottom to top: 1101.

In code

(255).toString(2)    // "11111111"
(255).toString(16)   // "ff"
parseInt("ff", 16)   // 255

Prefixes

Code often marks the base with a prefix: 0b for binary, 0o for octal, 0x for hex. Our converter accepts them.

Big numbers

Normal JavaScript numbers lose accuracy when they get huge. The Number Base tool on our Developer Converters page uses BigInt, so long values stay exact.

Type a number, choose its base, and you see all four forms at once. If you enter a digit that is not allowed, such as 9 in binary, it tells you.

Frequently asked questions

How do I convert binary to decimal quickly?

Write the place values from the right: 1, 2, 4, 8, 16 and so on. Add up the values where the binary digit is 1. For 1011 that is 8 + 2 + 1 = 11.

Why do colours use hex codes?

A colour like #2563EB is three bytes: red, green and blue, each from 0 to 255. Two hex digits hold exactly one byte (00 to FF), so hex is a short, exact way to write them.

What is octal used for today?

Mostly for file permissions on Linux and macOS, such as chmod 755. Each digit sets read, write and execute for the owner, the group and everyone else.

Can I convert very large numbers?

Yes. Our number base converter uses exact big-number arithmetic, so long IDs and 64-bit values are converted without rounding errors.

Try it now

Open the free Developer Converters. It runs in your browser, so nothing is uploaded.