Add, subtract, multiply and divide hexadecimal numbers, use bitwise AND, OR and XOR, and convert between hex and decimal, with every step shown.
Working
Works with whole numbers of any length using exact arithmetic. Negative numbers can be entered with a minus sign. Division gives the whole-number quotient and the remainder. AND, OR and XOR compare the bits of non-negative numbers.
A hex calculator adds, subtracts, multiplies and divides hexadecimal numbers, performs bitwise AND, OR and XOR, and converts between hexadecimal and decimal, showing every step. Each result is also shown in binary and octal, and the calculator uses exact arithmetic, so even very long hex numbers are handled without rounding.
For example, 1A3F + FF = 1B3E in hex, which is 6,719 + 255 = 6,974 in decimal. FF in hex is 255 in decimal, 2D is 45, and the decimal number 65,535 is FFFF in hexadecimal.
Hexadecimal, or hex, is a base-16 number system. It uses sixteen digits: 0 to 9 for the values zero to nine, and A, B, C, D, E and F for ten to fifteen. Each position is worth 16 times the one to its right: 1, 16, 256, 4,096 and so on. Hex is popular in computing because one hex digit represents exactly four binary digits (bits), so a byte of 8 bits is always two hex digits, from 00 to FF.
| Hex | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
| 10 | 16 | 1 0000 |
| FF | 255 | 1111 1111 |
Multiply each digit by its place value, a power of 16, and add the results. For 2D: 2 × 16 + 13 × 1 = 32 + 13 = 45. For FFFFFF, the largest six-digit hex number: 15 × 16⁵ + 15 × 16⁴ + … + 15 × 16⁰ = 16,777,215. That’s one less than the 16,777,216 colours available in 24-bit colour, because counting starts at 000000 for black.
Divide by 16 repeatedly and write down each remainder, using A to F for remainders of 10 to 15. Read the remainders from last to first. For 255: 255 ÷ 16 = 15 remainder 15 (F), and 15 ÷ 16 = 0 remainder 15 (F), giving FF. For 45: 45 ÷ 16 = 2 remainder 13 (D), and 2 ÷ 16 = 0 remainder 2, giving 2D.
Because each hex digit equals four bits, converting is quick: replace each hex digit with its four-bit pattern. 2D becomes 0010 1101. To go the other way, split the binary number into groups of four from the right and convert each group: 1111 0000 becomes F0. This is why programmers prefer hex for reading binary data: it’s four times shorter and still maps directly to the bits.
Add column by column from the right, as in decimal, but carry when a column reaches 16 instead of 10. For F + 1, 15 + 1 = 16, so write 0 and carry 1: the result is 10. 1A3F + FF = 1B3E.
Subtract column by column, borrowing 16 from the next column when needed. FF − 1A = E5, which is 255 − 26 = 229.
These work like decimal long multiplication and division, but are easiest to check by converting to decimal. 1F × A = 136 (31 × 10 = 310), and FF ÷ 10 = F remainder F (255 ÷ 16 = 15 remainder 15).
The web colour #FF5733 is a warm orange-red. Split it into three pairs: FF, 57 and 33. Converting each to decimal gives red = 255, green = 5 × 16 + 7 = 87 and blue = 3 × 16 + 3 = 51, so the colour is rgb(255, 87, 51). To lighten it, increase the green and blue values; to make pure red, use #FF0000. Three-digit shorthand codes double each digit, so #F53 means #FF5533 and #FFF means white, #FFFFFF.
This calculator shows negative results with a minus sign, such as −1A. Inside computers, negative numbers are usually stored as two’s complement, which looks very different in hex. In a 32-bit integer, −1 is stored as FFFFFFFF, and −16 as FFFFFFF0. If you see a large hex value starting with F in a debugger, it may actually be a small negative number. To find the value, subtract it from 100000000 (2³²) and add a minus sign: 100000000 − FFFFFFF0 = 10, so FFFFFFF0 is −16.
| Position | Power of 16 | Value |
|---|---|---|
| 1st (right) | 16⁰ | 1 |
| 2nd | 16¹ | 16 |
| 3rd | 16² | 256 |
| 4th | 16³ | 4,096 |
| 5th | 16⁴ | 65,536 |
| 6th | 16⁵ | 1,048,576 |
Four hex digits cover 0 to 65,535 (FFFF), the range of a 16-bit number, and eight cover 0 to 4,294,967,295 (FFFFFFFF), the range of a 32-bit number.
All three systems describe the same numbers; they just group them differently. Decimal is natural for people because we have ten fingers. Binary is natural for computers because circuits are either off or on. Hex sits in between: it’s compact enough for people to read and write, while mapping perfectly onto the binary that computers use. A 32-bit value such as 3,735,928,559 in decimal is a long string of 32 ones and zeros in binary, but only eight characters in hex: DEADBEEF, a value programmers sometimes use as a recognisable marker in memory.
Two other tools work well alongside this one: the binary calculator, to do binary arithmetic and convert binary to decimal, and the scientific notation calculator, to convert numbers to and from scientific notation.
Multiply each digit by its place value (1, 16, 256, …) and add the results, using A = 10 to F = 15. 2D = 2 × 16 + 13 = 45.
Divide by 16 repeatedly, write down the remainders (10–15 as A–F) and read them from last to first. 255 becomes FF.
255. It's the largest value that fits in one byte, because two hex digits cover 256 values from 00 to FF.
Only A, B, C, D, E and F, standing for 10 to 15.
Each hex digit represents exactly four bits, so hex is a compact, readable way to write binary data such as bytes, colours and memory addresses.
A code like #FF5733 has three pairs of hex digits for red, green and blue, each from 00 (none) to FF (full, 255).
It's a common prefix in programming that marks a number as hexadecimal, as in 0xFF. The calculator accepts it.
Add column by column from the right and carry 1 whenever a column reaches 16. F + 1 = 10 in hex.
No. ff, FF and fF all mean 255. The calculator shows results in capital letters.
Red 255, green 87 and blue 51, written rgb(255, 87, 51).
16. In hexadecimal, 10 means one sixteen and zero ones, just as decimal 10 means one ten and zero ones.
In 32-bit two's complement, the bit pattern FFFFFFFF represents −1. Unsigned, the same pattern is 4,294,967,295.
Replace each hex digit with its four-bit binary pattern. 2D becomes 0010 1101.
It's shorthand for #FFFFFF, which is white. Each digit is doubled, so #F53 means #FF5533.
256, from 00 to FF, which is exactly one byte.