Hex calculator

Add, subtract, multiply or divide two hex numbers and get the answer in hex, decimal, binary and octal. "Show the working" lays out the carries, borrows and long division step by step.

Show the working
Whole numbers only. A minus sign is allowed.
Checked bySharmina Rahman
Last updated · How we test

Runs in your browser. Nothing you type is uploaded.

How to use the hexadecimal calculator

  1. Enter two hex numbers. A 0x or # prefix is fine, and upper or lower case both work.
  2. Pick the operation: add, subtract, multiply, divide, modulo, power, AND, OR, XOR, NOT, or a left or right shift.
  3. Read the result in hex, with decimal, binary and octal underneath. Division also shows the remainder.
  4. Open "Show the working" to see each column, then copy or share the result.

Numbers of any length work, and a minus sign is allowed. The swap button between the boxes reverses the two numbers, which matters for subtraction and division.

What the calculator does at the limits

Negative answers, remainders, overflow and very long numbers are where hex calculators differ. Each sum below was entered into the calculator on this page, and the right column shows what came back.

SumWhat you get
5F - A03-9A4. A smaller number minus a bigger one gives a result with a minus sign.
7 ÷ 23 remainder 1
FF ÷ 0No result. The message says you cannot divide by zero.
2 ^ A400, which is 1024 in decimal
FFFFFFFFFFFFFFFFFFFF × FFFFFFFFFFFFFFFFFFFF (two 20-digit numbers)FFFFFFFFFFFFFFFFFFFE00000000000000000001, all 40 digits
7F + 1 with Number type set to Signed 8-bit80, with a note that 128 does not fit in signed 8-bit and wraps to -128
NOT F0 as Unsigned, then as Signed 8-bitF as unsigned and 0F as signed 8-bit. Both flip the same eight bits.
AB1D.3E - 2A2C.1F (numbers with a point)Not accepted. The message says to use whole numbers only.
The hex calculator set to Add and Signed 8-bit with 7F plus 1. A message says the exact answer is 128, which does not fit in signed 8-bit, so it wraps to -128. The result in hex is 80.
7F + 1 as a signed 8-bit sum. The calculator gives 80 and says the true answer, 128, did not fit.

Hex addition: how to add hexadecimal numbers

Hex addition of 2B9 and FA7 in columns with carries shown above: 9 + 7 = 16 writes 0, B + A + 1 = 22 writes 6, 2 + F + 1 = 18 writes 2, and the final carry gives 1260.

Hex addition works like ordinary column addition, except a column carries when it reaches 16 instead of 10. Add the two digits in decimal; if the total is 16 or more, subtract 16, write that as a hex digit and carry 1 to the next column.

SumIn decimalHex result
8 + 81610
9 + 71610
A + 61610
F + 11610
A + B2115
C + D2519
F + F301E
FF + 1256100

Hex subtraction

Hex subtraction of 5F from A03 with two borrows: 3 minus F borrows to make 19 minus 15 = 4, the middle column becomes 16 minus 6 = A, and the left column is 9, giving 9A4.

When the top digit is smaller than the one below it, borrow 1 from the column to the left. That borrowed 1 is worth 16 in the current column. In A03 - 5F, 3 minus F needs a borrow: 19 minus 15 is 4. The middle 0 has lent its value, so it borrows again: 16 minus 1 minus 5 is 10, written A. The answer is 9A4, and 2563 minus 95 is 2468 confirms it.

Hex multiplication

Multiply the first number by each digit of the second, working in decimal and converting each row back to hex. Shift each row one place left for each position, then add the rows. For 2B × 1C: 2B × C is 43 × 12 = 516, or 204 in hex. 2B × 1 is 2B, shifted one place to 2B0. Adding the rows, 204 + 2B0 = 4B4, which is 1204, the same as 43 × 28.

ProductDecimalHex
2 × 81610
4 × 41610
A × A10064
F × 2301E
F × F225E1
10 × 10256100

Hex division

Long division in hex brings down one digit at a time and asks how many times the divisor fits, from 0 to F. For 3E8 ÷ A: 3 is too small, so take 3E (62). A (10) fits 6 times with 2 left over. Bring down the 8 to make 28 in hex, which is 40, and A fits 4 times exactly. The answer is 64, the same as 1000 ÷ 10 = 100.

Three hex problems worked through

F213 - EC11

Work from the right. 3 - 1 = 2, then 1 - 1 = 0. In the third column 2 is smaller than C, so borrow 1 from the F, which makes 18 - 12 = 6. The F has become E, and E - E = 0. The answer is 602. In decimal that is 61971 - 60433 = 1538.

The hex calculator with F213 minus EC11 and the result 602. Show the working is open: it gives the sum in decimal and lays out the subtraction in columns with a small b above the F to mark the borrow.
F213 - EC11 with the working open. The small b above the F marks the column that lent 1.

0x0000AA00 + 0xFFFFFFFC

As plain unsigned numbers the sum is 10000A9FC, which needs 33 bits. A 32-bit register drops the top bit and keeps 0000A9FC. Set Number type to Signed 32-bit and the calculator shows that value. Read as a signed number, FFFFFFFC is -4, so the sum is 43520 - 4 = 43516.

The hex calculator set to Add and Signed 32-bit with 0x0000AA00 plus 0xFFFFFFFC. The 32-bit result is 0000A9FC, and the decimal value is 43516.
The same sum as a signed 32-bit addition. The result is 0000A9FC, or 43516.

AB1D.3E - 2A2C.1F

The calculator takes whole numbers only, so this one is done by hand. Line up the points and subtract as usual. After the point, E - F needs a borrow: 30 - 15 = 15, which is F. The 3 has become 2, and 2 - 1 = 1, so the fraction is .1F. Before the point, D - C = 1. Then 1 - 2 needs a borrow: 17 - 2 = 15, which is F. The B has lent 1 and is now A, and A - A = 0. Last, A - 2 = 8. The answer is 80F1.1F.

AND, OR, XOR and shifts in hex

Bitwise operations work on the binary behind each hex digit. With F0 and 3C: AND gives 30, OR gives FC and XOR gives CC. Each hex digit is four bits, so shifting left by 4 adds a 0 on the right: 1 << 4 = 10. For XOR of more than two values, or of text, use the XOR calculator.

Hex digits and their values

HexDecimalBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

Every hex digit stands for four bits, which is why hex is such a compact way to write binary. The hex to decimal converter explains place values if you want to check a result by hand.

Hex math in Python, JavaScript and Excel

  • Python: hex(0x2B9 + 0xFA7) returns '0x1260', using Python's built-in hex() function.
  • JavaScript: (0x2B9 + 0xFA7).toString(16) returns "1260".
  • Excel and Google Sheets: =DEC2HEX(HEX2DEC("2B9")+HEX2DEC("FA7")) returns 1260. Microsoft's page on the DEC2HEX function explains the optional places argument for leading zeros.
  • The Windows Calculator has a Programmer mode with a HEX setting for quick sums.

Frequently asked questions

What is F + 1 in hex?

10. F is 15, and 15 + 1 = 16, which is written 10 in hex.

What is FF + 1?

100, which is 256 in decimal.

How do you subtract hex numbers?

Column by column from the right. When the top digit is smaller, borrow 1 from the left; it is worth 16 in the current column.

Can I use negative hex numbers?

Yes, with a minus sign, and results can be negative too. For the two's complement form that programs use, try the two's complement calculator.

Is there a size limit?

No practical one. The calculator uses whole-number arithmetic with no fixed size, so 64-bit values and longer come out exact.

Scroll to Top