Tech & everyday
Hex, binary and decimal converter
Convert between binary, octal, decimal, hexadecimal and any base up to 36 — with the bit pattern laid out so you can see what the number is doing, not just what it says.
This number in every common base
Positional notation, whatever the base
Every base works the same way: each digit position is worth the base raised to that position’s power. In decimal, 253 means 2×100 + 5×10 + 3×1. In hexadecimal, FD means 15×16 + 13×1, which is also 253.
Bases above ten need extra symbols, so letters take over: A is 10 through F is 15 in hex, continuing to Z as 35 in base 36. Base 36 is the highest you can reach with digits and the Latin alphabet, which is why URL shorteners and short IDs so often use exactly that.
Why hexadecimal and not something else
Because 16 is 2⁴, each hex digit maps to exactly four bits with no remainder. That makes conversion between hex and binary a lookup rather than a calculation, and it means a byte is always precisely two hex digits.
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Octal has the same property with three bits per digit, which is why Unix file permissions are octal: read, write and execute are exactly three bits, so 755 reads directly as rwxr-xr-x.
Two’s complement, or how computers hold negatives
Hardware has no minus sign, so negative numbers are represented by two’s complement: invert every bit and add one. In eight bits, −1 is 11111111 and −128 is 10000000.
The scheme is used because addition then works identically for positive and negative values, with no special case. Its one asymmetry is that the range runs from −128 to +127 rather than symmetrically, since zero occupies one of the positive slots. That is the origin of the classic bug where negating the most negative integer returns itself.
Where the limits bite
JavaScript, which runs this page, holds all numbers as 64-bit floats and can only represent integers exactly up to 2⁵³ − 1, about 9.007 quadrillion. Beyond that, conversions silently lose precision, so this calculator stops rather than showing a plausible wrong answer. The same limit is why APIs returning 64-bit IDs usually send them as strings.
Common questions
How do I convert hex to decimal by hand?
Multiply each digit by 16 raised to its position, counting from zero on the right. For 2F: F is 15, so 2×16 + 15 = 47. For longer values, working right to left and keeping a running total is less error-prone than doing all the powers first.
Why is 255 significant?
It is the largest value eight bits can hold, so it is the maximum for one byte. That is why colour channels run 0–255, why 255.255.255.255 is the all-ones IPv4 address, and why so many limits in older software stop at 255 or its neighbours.
What is the difference between 0x, 0b and 0o prefixes?
They tell a compiler or interpreter which base a literal is written in: 0x for hexadecimal, 0b for binary, 0o for octal. So 0x1F, 0b11111 and 0o37 all mean 31. This calculator strips them automatically when they match the base you have selected.
What is base 36 used for?
Compact identifiers. Using digits plus the 26 Latin letters packs more value into fewer characters than decimal, so short URLs, invoice references and database IDs often use it. Base 62 goes further by treating upper and lower case as distinct, though that makes IDs harder to read aloud.