About the Hex Calculator
Hexadecimal is base sixteen. It needs sixteen digits and we only have ten numerals, so the letters A to F stand in for ten to fifteen.
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
That single borrowing of six letters is the only unfamiliar thing about it. Everything else works exactly like decimal, with columns worth 1, 16, 256, 4096 and so on.
Hex exists in computing for one reason: one hex digit is exactly four bits. That makes it the most compact notation that still maps cleanly onto binary, which is why colour codes, memory addresses, hashes and byte values are all written in it.
This calculator does hex arithmetic, converts to decimal and binary, and decodes hex colour codes.
How to Use the Hex Calculator
Arithmetic adds, subtracts, multiplies or divides two hex numbers.
Convert and inspect gives the decimal and binary equivalents with the place values spelled out.
Read a hex colour code decodes #3A7BD5 into its red, green and blue components.
Case does not matter, and a leading 0x is accepted and ignored.
Reading Hexadecimal
Each column is sixteen times the one to its right:
place: 4096 256 16 1
16³ 16² 16¹ 16⁰
FF = 15 × 16 + 15 × 1 = 255
1A = 1 × 16 + 10 × 1 = 26
FFFF = 15×4096 + 15×256 + 15×16 + 15 = 65535
Two useful landmarks: FF is 255, the largest value in one byte, and FFFF is 65535, the largest in two. Those two numbers appear constantly, and recognising them saves a lot of conversion.
Why four bits per digit
Four binary digits give exactly sixteen combinations, which is exactly the range of one hex digit:
0 = 0000 4 = 0100 8 = 1000 C = 1100
1 = 0001 5 = 0101 9 = 1001 D = 1101
2 = 0010 6 = 0110 A = 1010 E = 1110
3 = 0011 7 = 0111 B = 1011 F = 1111
So converting hex to binary is a lookup, not a calculation. A5 is 1010 0101 — read the table twice and you are done. Going back, group the bits in fours from the right and read each group.
This is the whole practical argument for hexadecimal. A 32-bit value is eight hex digits or thirty-two ones and zeros, and one of those you can read aloud.
Hex Arithmetic
The same as decimal, carrying at sixteen rather than ten.
FF (255)
+ 1A ( 26)
────
119 (281)
Working right to left: F + A is 15 + 10 = 25, which is 19 in hex — write the 9, carry the 1. Then F + 1 + 1 = 17, which is 11 in hex — write the 1, carry the 1. The leading carry gives 119.
The only real difficulty is holding in mind that A to F are values. Once F + A = 19 looks as natural as 9 + 6 = 15, hex arithmetic is no harder than decimal.
Division here is integer division: a quotient and a remainder, as a processor does it.
Hex Colour Codes
This is where most people meet hexadecimal, and the scheme is simpler than it looks.
#3A7BD5 is three pairs:
3A = 58 red
7B = 123 green
D5 = 213 blue
Each pair is one byte, so each channel runs from 00 (none) to FF (full) — 0 to
- That is why colour codes are six digits: three channels, two digits each,
because two hex digits are exactly one byte.
#FF0000 full red
#00FF00 full green
#0000FF full blue
#FFFFFF all three at full = white
#000000 none of any = black
#808080 all three equal = mid grey
Equal channels always mean grey. If the three pairs match, the colour has no hue at all — only brightness.
The three-digit shorthand
#F00 is valid CSS and means #FF0000. Each digit is doubled, not padded with zeros — so #F00 is full red, not the very dark #0F0000.
This catches people out, and it is why the shorthand can only express colours whose pairs happen to repeat. #3A7BD5 has no three-digit form.
Step-by-Step Example
Converting FF to decimal.
F = 15, so:
15 × 16¹ + 15 × 16⁰
240 + 15 = 255
Converting 255 to hex.
255 ÷ 16 = 15 remainder 15
15 ÷ 16 = 0 remainder 15
Reading the remainders upwards: 15, 15 → F, F → FF
Adding FF + 1A.
F + A = 25 = 19 hex → write 9, carry 1
F + 1 + 1 = 17 = 11 hex → write 1, carry 1
Result: 119 hex = 281 decimal ✓
Decoding a colour.
#3A7BD5
3A → 3 × 16 + 10 = 58 red
7B → 7 × 16 + 11 = 123 green
D5 → 13 × 16 + 5 = 213 blue
→ rgb(58, 123, 213), a medium blue
Understanding Your Result
The result is in hexadecimal, or as an rgb triple in colour mode.
The decimal line gives the same value in base ten.
The binary line shows the bits, and how many bits the hex digits represent.
The working shows the conversion or the arithmetic in both bases.
The what this means line gives the byte width — whether the value fits in one, two or four bytes — or, for a colour, the channel percentages and which is strongest.
When Should You Use This Calculator?
Web design. Converting between hex colours and rgb, and understanding what a code means before you adjust it.
Programming. Memory addresses, bit masks, error codes and character codes are conventionally hex.
Debugging. Hex dumps of files and network packets, where two digits per byte makes patterns visible.
Networking. MAC addresses are six hex bytes; IPv6 addresses are hex throughout.
Graphics. Colour values, alpha channels and pixel formats.
Checksums and hashes. MD5 and SHA outputs are hex strings, and this calculator converts them exactly however long they are.
Coursework. Hex arithmetic and conversion are standard computing topics.
Common Mistakes
Reading letters as letters. In 1A, the A is a digit worth ten. The value is 26.
Forgetting to carry at sixteen. F + 1 is 10 in hex, not 16 or G. There is no digit above F.
Padding the three-digit colour shorthand with zeros. #F00 doubles to #FF0000, not #0F0000. Doubling, not padding.
Assuming a colour pair maxes at 99. It goes to FF, which is 255. #99 is 153, not the maximum.
Mixing up digit count and byte count. Two hex digits are one byte. Eight hex digits are four bytes, not eight.
Dropping the 0x prefix mid-calculation. It marks the base and is not part of the value. 0x10 is sixteen; 10 on its own is ambiguous.
Trusting parseInt on long hex strings. It loses precision past about sixteen digits, which is well short of a hash. This calculator uses exact arithmetic throughout.
Confusing hex FF with 100%. FF is the maximum of a byte, which is 255. There is no value of 256 in a single byte — 0 to 255 is 256 values, and that is the whole range.