Hex Calculator

Add, subtract, multiply or divide two hexadecimal numbers, or convert a number between hex and decimal.

Hexadecimal Calculation

Enter two hex numbers, using the digits 0 to 9 and the letters A to F, and pick an operation.

Hex to Decimal

Convert a hexadecimal number to a decimal number.

Decimal to Hex

Convert a whole decimal number to hexadecimal.

Hex, decimal and binary

DecimalHexBinaryDecimalHexBinary
000000881000
110001991001
22001010A1010
33001111B1011
44010012C1100
55010113D1101
66011014E1110
77011115F1111
Quick answer. Hex is base 16, using 0 to 9 and A to F. 8AB + B78 = 1423 in hex (2,219 + 2,936 = 5,155). DAD in hex is 3,501 in decimal, and 170 in decimal is AA in hex.

How hexadecimal works

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 digitDecimalBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

Worked example with the default numbers

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).

OperationHex resultDecimal check
8AB + B7814232,219 + 2,936 = 5,155
8AB − B78-2CD2,219 − 2,936 = -717
8AB × B786369282,219 × 2,936 = 6,514,984
8AB ÷ B780 remainder 8AB2,219 ÷ 2,936 = 0 remainder 2219

Converting hex to decimal

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.

Value of each place in a 4-digit hex numberEach place is worth 16 times the one to its right: 1, 16, 256 and 4,096.Value of each place in a 4-digit hex number16^34,09616^225616^11616^01
The places grow by a factor of 16.

Converting decimal to hex

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:

DivideQuotientRemainderHex digit
3,501 ÷ 1621813D
218 ÷ 161310A
13 ÷ 16013D

Reading the digits bottom to top gives DAD. The page’s decimal-to-hex default is 170, which is AA (10 × 16 + 10).

Digits needed to write the number 3,501 in three basesHex is compact: 3,501 is 110110101101 in binary but just DAD in hex.Digits needed to write the number 3,501 in three basesBinary12Decimal4Hexadecimal (DAD)3
Hex is a shorter way to write the same value.

Hex and binary

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 byteDecimalBinary
00000000000
0F1500001111
101600010000
7F12701111111
8012810000000
AA17010101010
FF25511111111

Where hex is used

  • Web colors: #FF8800 sets red to FF (255), green to 88 (136) and blue to 00 (0), which is orange.
  • Memory addresses and MAC addresses: long values are written in hex.
  • Character codes and byte values: programmers read hex when they debug.
  • Unicode: code points are written in hex, such as U+00E9.
The orange color #FF8800: red, green and blue amounts (0 to 255)Each pair of hex digits is one color channel from 00 (none) to FF (full).The orange color #FF8800: red, green and blue amounts (0 to 255)Red (FF)255Green (88)136Blue (00)0
A color is three hex pairs.
Color codeNameRedGreenBlue
#FF0000Red25500
#00FF00Green02550
#0000FFBlue00255
#FF8800Orange2551360
#FFFFFFWhite255255255
#808080Gray128128128

The CSS specification defines these six-digit codes as hex colors; every pair is one channel.

Handy values to remember

HexDecimalWhy it matters
1016The base itself
64100One hundred
FF255The largest byte value
100256One more than a byte holds
3E81,000One thousand
FFFF65,535The largest 16-bit value
FFFFFF16,777,215The 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.

Entering numbers

  • Use digits 0 to 9 and letters A to F, upper or lower case. Results are shown in upper case.
  • A 0x prefix, such as 0x8AB, is accepted and ignored.
  • Negative whole numbers use a minus sign.
  • Only whole numbers are supported. Fractions and two's complement are not used.
  • The sums are exact for numbers of any size.

Common mistakes

  • Using letters beyond F, such as G.
  • Forgetting that D is 13, not 4, when converting by hand.
  • Confusing the decimal number 170 with the hex number 170, which is 368 in decimal.
  • Dividing and expecting a fraction. Division gives a whole quotient and a remainder.

How to read your result

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.

The calculator works with whole numbers. Hardware or exam questions that use a fixed word size may handle negative numbers differently.

What to do next

Common questions

How do you add hex numbers?

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.

What do the letters A to F mean in hex?

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.

How do I convert hex to decimal?

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.

How do I convert decimal to hex?

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.

Why is hex used with binary?

One hex digit equals exactly four binary digits, so a byte is two hex digits. It is a compact way to write binary values.

Does the calculator accept a 0x prefix?

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)

More Math Calculators

Pick another tool to jump straight to it.