Tools
EN

Hex Calculator

A hexadecimal calculator for addition, subtraction, multiplication and division, plus bitwise AND, OR, XOR, NOT and shifts. Numbers of any size are calculated exactly, and negative results are also shown in two's complement.

Hexadecimal
Decimal
Binary

Private: your data is processed in your browser and never uploaded.

How to use the hex calculator

  1. Enter two hex numbers, for example 8AB and B78. A minus sign and prefixes such as 0x are allowed.
  2. Pick the operation. The result updates instantly in hex, decimal and binary; division also shows the remainder.
  3. For negative results and NOT, choose the bit width (8, 16, 32 or 64 bits) to see the two's-complement value.

How to add hex numbers

Add the digits column by column from the right, exactly as in decimal. The only difference: when a column adds up to 16 or more, write down the sum minus 16 and carry 1 to the next column. Example: 8AB + B78.

ColumnDigitsSumWriteCarry
16⁰B + 811 + 8 = 1931
16¹A + 7 + 110 + 7 + 1 = 1821
16²8 + B + 18 + 11 + 1 = 2041
16³carry11–

Reading the written digits from the bottom row up (highest column first) gives 1423. Check in decimal: 2219 + 2936 = 5155 = 1423 hex.

Hex subtraction, negative results and two's complement

Subtraction works with borrowing: if the top digit is smaller, borrow 16 from the next column. B78 − 8AB: 8 − B needs a borrow, 8 + 16 − 11 = 13 = D; then 7 − 1 − A needs a borrow, 6 + 16 − 10 = 12 = C; finally B − 1 − 8 = 2, so the result is 2CD.

If the second number is larger, the result is negative. The calculator shows it with a minus sign (5 − 8 = −3) and also as the bit pattern a computer stores: in 8-bit two's complement −3 is 2⁸ − 3 = 253 = FD, in 16 bits FFFD. By hand, negate a number by inverting all bits and adding 1: 03 = 0000 0011 → 1111 1100 → 1111 1101 = FD.

Bitwise operations: AND, OR, XOR, NOT and shifts

Bitwise operations compare the numbers bit by bit, which is why programmers use them for flags, masks and permissions. Examples with 3C = 0011 1100 and 0F = 0000 1111:

OperationRuleResult
3C AND 0F1 only where both bits are 10C
3C OR 0F1 where at least one bit is 13F
3C XOR 0F1 where the bits differ33
NOT 3C (8-bit)every bit flippedC3
3C << 1shift left = multiply by 278
3C >> 2shift right = divide by 40F

Frequently asked questions

How do you multiply hex numbers?

The same way as in decimal, but every partial product is written in base 16. It is often easier to convert to decimal, multiply and convert back: 1A × 10 = 26 × 16 = 416 = 1A0. Multiplying by 10 hex (16) simply appends a zero, just like multiplying by 10 in decimal.

What happens when I divide hex numbers?

The calculator performs integer division and shows the quotient and the remainder: 1423 ÷ 10 = 142 remainder 3. Dividing by zero is reported as an error.

Why does NOT give different results for different bit widths?

NOT flips every bit of a fixed-size value, so the result depends on how many bits there are: NOT 3C is C3 in 8 bits but FFC3 in 16 bits. Auto width picks the smallest standard width (8, 16, 32 or 64 bits) that holds the number.

Can the hex calculator handle large numbers?

Yes. All operations use arbitrary-precision integers, so 64-bit, 128-bit and even longer values are calculated exactly, without the overflow or rounding of an ordinary calculator.