Add, subtract, multiply or divide two hexadecimal numbers, or convert a number between hex and decimal.
Enter two hex numbers, using the digits 0 to 9 and the letters A to F, and pick an operation.
Convert a hexadecimal number to a decimal number.
Convert a whole decimal number to hexadecimal.
| Decimal | Hex | Binary | Decimal | Hex | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | 10 | A | 1010 |
| 3 | 3 | 0011 | 11 | B | 1011 |
| 4 | 4 | 0100 | 12 | C | 1100 |
| 5 | 5 | 0101 | 13 | D | 1101 |
| 6 | 6 | 0110 | 14 | E | 1110 |
| 7 | 7 | 0111 | 15 | F | 1111 |
Hexadecimal, or hex, counts in base 16. It needs sixteen digits, so after 0 to 9 it uses the letters A to F for the values 10 to 15. Each place is worth sixteen times the one to its right. The hex number 2F is 2 × 16 + 15, which is 47 in decimal. Hex is popular in computing because one hex digit stands for exactly four binary digits, so long binary numbers become short and easy to read.
| Hex digit | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
The page opens with 8AB and B78, which are 2,219 and 2,936 in decimal. Adding them gives 1423 in hex (2,219 + 2,936 = 5,155). Column by column: B + 8 = 19, which is 13 hex, so write 3 and carry 1; and so on until the sum is 1423. Subtracting gives -2CD (-717), multiplying gives 636928 (6,514,984) and dividing 8AB by B78 gives a quotient of 0 and a remainder of 8AB (in decimal 0 remainder 2219).
| Operation | Hex result | Decimal check |
|---|---|---|
| 8AB + B78 | 1423 | 2,219 + 2,936 = 5,155 |
| 8AB − B78 | -2CD | 2,219 − 2,936 = -717 |
| 8AB × B78 | 636928 | 2,219 × 2,936 = 6,514,984 |
| 8AB ÷ B78 | 0 remainder 8AB | 2,219 ÷ 2,936 = 0 remainder 2219 |
Multiply each digit by 16 raised to its position, counting from 0 at the right, and add the results. DAD is 13 × 256 + 10 × 16 + 13 = 3,501, the page’s default hex-to-decimal example. The number 8AB is 8 × 256 + 10 × 16 + 11 = 2,219.
Divide the number by 16 repeatedly, keep the remainders and write 10 to 15 as A to F. Reading them from the last to the first gives the hex number. For 3,501:
| Divide | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 3,501 ÷ 16 | 218 | 13 | D |
| 218 ÷ 16 | 13 | 10 | A |
| 13 ÷ 16 | 0 | 13 | D |
Reading the digits bottom to top gives DAD. The page’s decimal-to-hex default is 170, which is AA (10 × 16 + 10).
One hex digit equals exactly four binary digits (bits), so a byte of 8 bits is two hex digits, with values from 00 to FF, or 0 to 255 in decimal. To convert, replace each hex digit with its four bits: A is 1010, so AA is 10101010, which is 170 in decimal. The Binary Calculator does arithmetic in base 2.
| Hex byte | Decimal | Binary |
|---|---|---|
| 00 | 0 | 00000000 |
| 0F | 15 | 00001111 |
| 10 | 16 | 00010000 |
| 7F | 127 | 01111111 |
| 80 | 128 | 10000000 |
| AA | 170 | 10101010 |
| FF | 255 | 11111111 |
| Color code | Name | Red | Green | Blue |
|---|---|---|---|---|
| #FF0000 | Red | 255 | 0 | 0 |
| #00FF00 | Green | 0 | 255 | 0 |
| #0000FF | Blue | 0 | 0 | 255 |
| #FF8800 | Orange | 255 | 136 | 0 |
| #FFFFFF | White | 255 | 255 | 255 |
| #808080 | Gray | 128 | 128 | 128 |
The CSS specification defines these six-digit codes as hex colors; every pair is one channel.
| Hex | Decimal | Why it matters |
|---|---|---|
| 10 | 16 | The base itself |
| 64 | 100 | One hundred |
| FF | 255 | The largest byte value |
| 100 | 256 | One more than a byte holds |
| 3E8 | 1,000 | One thousand |
| FFFF | 65,535 | The largest 16-bit value |
| FFFFFF | 16,777,215 | The largest 24-bit value, white as a web color |
Programmers mark hex numbers with a prefix so they are not mistaken for decimal: 0x in many languages, # for colors in CSS and &H in some older languages. This calculator accepts 0x, and ignores it.
The large line is the hex result, with both numbers in hex and the same calculation in decimal underneath so you can check it. The other two tools convert one number at a time. For binary arithmetic use the Binary Calculator, and for very large decimal numbers the Big Number Calculator.
Add the digits column by column from the right, using decimal values for the letters. When a column reaches 16 or more, write the remainder and carry 1. For example, 8AB + B78 is 1423.
They stand for the values 10 to 15: A is 10, B is 11, C is 12, D is 13, E is 14, and F is 15.
Multiply each digit by 16 raised to its position, counting from 0 at the right, and add them up. DAD is 13 x 256 + 10 x 16 + 13, which is 3,501.
Divide the number by 16 repeatedly and keep the remainders, writing 10 to 15 as A to F. Reading the remainders from last to first gives the hex number.
One hex digit equals exactly four binary digits, so a byte is two hex digits. It is a compact way to write binary values.
Yes. A leading 0x is ignored, so 0x8AB and 8AB give the same result.
Sources: CS50: Lecture 0, binary and computers; W3C: CSS Color Module Level 4 (hex colors)
Pick another tool to jump straight to it.