Hex Calculator: Base 16 Without the Headache
Base 16 explained through the arithmetic that trips people up, plus how colour codes decode.
Quick answer: A hex calculator adds, subtracts, multiplies and converts numbers in base 16, where the digits run 0 to 9 and then A to F for 10 to 15. 2F plus 1A is 49 in hex, which is 73 in decimal. It also decodes colour codes: the 3C in #3C6E71 is 60.
Base 16 exists for one reason. A single hex digit maps exactly onto four binary bits, so a byte is always two hex digits and never anything awkward. FF is 255, the largest value one byte can hold.
Why base 16 and not something friendlier
Binary is honest and unreadable. The byte 11111111 takes eight characters to say what FF says in two, and a 32-bit address written in binary is a wall of digits nobody can check by eye. Decimal is readable but does not line up with bits at all, so 255 gives you no hint that it is the boundary of anything.
Hex sits between the two. Each digit is one nibble of four bits, each pair of digits is one byte, and the boundaries stay visible. That is why memory addresses, colour codes, MAC addresses and error codes are all written in it rather than in decimal.
Run your own numbers
It is free, there is no sign-up, and it works on your phone.
Open the Hex CalculatorDoing it by hand
Addition works exactly like decimal, you just carry at 16 instead of 10. Take 2F + 1A. The right column is F + A, which is 15 + 10 = 25. Twenty-five is 16 plus 9, so write down 9 and carry 1. The left column is 2 + 1 + 1 = 4. The answer is 49. Check it in decimal: 47 + 26 = 73, and 49 in hex is 4 x 16 + 9 = 73.
Where the carry catches people out
The instinct is to carry at 10, which quietly produces an answer that looks plausible and is wrong. A0 minus 3F is a good test. Borrowing gives you 16 + 0 - 15 = 1 in the right column, then 9 - 3 = 6 on the left, so the answer is 61. In decimal that is 160 - 63 = 97, and 61 in hex is 6 x 16 + 1 = 97. If you got 71, you borrowed 10 instead of 16.
Multiplication is where hand calculation stops being worth the effort. 1F x 3 is 31 x 3 = 93 in decimal, which converts back to 5D. Perfectly doable, but three digits in you will want the calculator.
How to use the hex calculator
Type both values into the input fields without the 0x or # prefix, choose the operation, and read the result. Most versions show the answer in hex, decimal and binary at the same time, which is the fastest way to check yourself. Letters are case-insensitive, so 3c6e71 and 3C6E71 are the same value.
Converting the other way
Decimal to hex is repeated division by 16, keeping the remainders and reading them bottom to top. Take 1000. Divide by 16: 62 remainder 8. Divide 62 by 16: 3 remainder 14, which is E. Divide 3 by 16: 0 remainder 3. Reading upward gives 3E8. Verify it: 3 x 256 + 14 x 16 + 8 = 768 + 224 + 8 = 1000.
Colour codes are simply three of those pairs in a row. In #3C6E71, 3C is 3 x 16 + 12 = 60 red, 6E is 110 green, and 71 is 113 blue. That is also why #FFFFFF is white, at 255 of each channel, and #000000 is black.
Common questions
What does the 0x prefix mean? It is a marker, used in C and most languages descended from it, saying the digits that follow are hex rather than decimal. Without it, 20 is ambiguous. 0x20 is unambiguously 32. Web colour codes use # for the same job, and older assembly sometimes uses a trailing h instead.
Why do hex numbers use letters? Base 16 needs sixteen single-character digits and the decimal system only supplies ten. A through F fill the gap for 10, 11, 12, 13, 14 and 15. There is nothing special about those particular letters, they were just the next characters available on a keyboard.
Is hex the same as binary? They express the same values in different notation. Any hex digit expands to exactly four binary digits, so F is 1111 and 3 is 0011, which makes 3F equal to 00111111. Converting between the two is mechanical, which is not true of converting either one to decimal.
Where will I actually run into hex? Colour codes in CSS and design tools, memory addresses in a debugger, hash values, MAC addresses, file permission masks, and Windows error codes such as 0x80070005. It turns up far more often than most alternative number systems, including the Roman numerals most of us spent longer learning at school, and for one-off conversions any decent collection of free math calculators will include one.