Skip to content
thecalculatorstudio

Hex Calculator: Add, Subtract, Multiply, Divide

Enter two hexadecimal numbers and pick an operation. You get the answer in hex, decimal, binary and octal, with the remainder for division, exact for up to 16 hex digits (64 bits).

Last reviewed

Up to 16 hexadecimal digits each. A 0x prefix, spaces and underscores are fine.

FF + 1

100

in hexadecimal · 9 bits

Binary
1 0000 0000
Decimal
256
Hexadecimal
100
Octal
400

Whole numbers only, and exact: the answer is worked in arbitrary-size integers, not floating point. Division gives a whole-number quotient and a remainder. AND, OR and XOR need numbers of 0 or more.

What hexadecimal is

Hexadecimal, or hex, is the number system with sixteen digits. It uses 0 to 9, and then the letters A to F for the values ten to fifteen:

Digit A B C D E F
Value 10 11 12 13 14 15

Each place is worth 16 times the one to its right: 1, 16, 256, 4,096 and so on. So FF means 15 × 16 + 15 = 255, and 1A3 means 1 × 256 + 10 × 16 + 3 = 419.

Why hex is used

One hex digit is exactly four bits (0000 to 1111), so a byte is two hex digits and a 32-bit number is eight. Long binary strings become short and readable. Hex is used for memory addresses, colour codes, file bytes and error codes. A web colour such as #FF8000 is three bytes: red FF (255), green 80 (128) and blue 00 (0).

The same relationship lets you convert between hex and binary digit by digit. A is 1010 and F is 1111, so AF is 1010 1111. See the binary calculator for the bits.

Reference values

Hex Decimal
0xFF 255
0x100 256
0x1000 4,096
0xFFFF 65,535
0x7FFFFFFF 2,147,483,647
0xFFFFFFFF 4,294,967,295
0xFFFFFFFFFFFFFFFF 18,446,744,073,709,551,615

The four operations

Addition. Add each column, and if it reaches 16 or more, write the remainder after taking out 16 and carry 1. A + 5 = 10 + 5 = 15 = F. FF + 1: F + 1 = 16, write 0 carry 1; F + 0 + 1 = 16, write 0 carry 1; the carry gives 1. The result is 100, which is 255 + 1 = 256.

Subtraction. Borrow 16 when the top digit is smaller. 2F − 1A = 47 − 26 = 21, which is 15 in hex.

Multiplication. 1A × 3 = 26 × 3 = 78. In hex, 78 = 4 × 16 + 14 = 4E. Do it column by column: A × 3 = 30 = 1 × 16 + 14, so write E and carry 1; then 1 × 3 + 1 = 4.

Division. 100 ÷ 7 is 256 ÷ 7 = 36 remainder 4. In hex that is 24 remainder 4. Check: 7 × 0x24 + 4 = 7 × 36 + 4 = 256 = 0x100. The long division calculator shows the same method in decimal.

AND, OR and XOR

These work on the bits of each hex digit. AND keeps a 1 only where both numbers have one, OR where either does, XOR where they differ.

  • FF AND 0F = 0F (keeps the low half).
  • FF OR 0F = FF.
  • FF XOR 0F = F0 (flips the low half).
  • F0F0 AND FF00 = F000.

AND with a “mask” is how programs pick out a few bits from a larger value.

Common mistakes

  • Treating the letters as variables. A to F are digits worth 10 to 15.
  • Reading 10 as ten. In hex, 10 is sixteen, and 100 is 256.
  • Forgetting that a carry happens at 16, not at 10. 9 + 1 = A, and F + 1 = 10.
  • Mixing up 0x and #. 0x marks a hex number in code, and # marks a hex colour. Neither is part of the number.
  • Expecting a fraction or two’s complement. The calculator is for whole numbers, and shows a negative answer with a minus sign.

How it is calculated

Each number is read digit by digit as a whole number in exact integer arithmetic (up to 16 hex digits, which is 64 bits), the operation is done on the integers, and the answer is written back in hex, decimal, binary and octal. Division gives the quotient rounded toward zero and the remainder, so that divisor × quotient + remainder equals the first number. AND, OR and XOR act on the bits of the two numbers. Nothing goes through floating point.

Frequently asked questions

What is hexadecimal?

The base-16 number system. It uses the digits 0 to 9 and then A to F for the values 10 to 15, and each place is worth 16 times the one to its right. FF is 15 × 16 + 15 = 255.

How do you add hexadecimal numbers?

Add column by column from the right, and carry when a column reaches 16 or more, writing the leftover in hex. A + 5 = 10 + 5 = 15 = F. FF + 1 is 255 + 1 = 256, which is 100 in hex, because each F carries over to the next column.

How do you convert hex to decimal or binary?

To decimal, multiply each digit by its place value (1, 16, 256, 4,096 …) and add them: 1A3 is 256 + 160 + 3 = 419. To binary, write each hex digit as four bits: A is 1010, F is 1111, so AF is 10101111. The results show all four bases.

Why do programmers use hex?

Because one hex digit is exactly four bits, so a byte is two hex digits and long binary numbers become short and readable. Web colours such as #FF8000 are three bytes: red 255, green 128 and blue 0.

How big a hex number can this handle?

Up to 16 hex digits for each number, which is 64 bits, up to FFFFFFFFFFFFFFFF = 18,446,744,073,709,551,615. The answer can be longer, and it is worked in exact whole-number arithmetic, so nothing is rounded.

Does it work with lower case, a 0x prefix, or negatives?

Lower and upper case both work, and a leading 0x is allowed. A minus sign is allowed for adding, subtracting, multiplying and dividing and shows as a minus in the answer, not in two's complement. AND, OR and XOR need numbers of 0 or more.

Related calculators

Sources