acalculator

What is the answer in hex?

Type two hexadecimal numbers and pick an operation. The hex calculator shows the exact result in hex, decimal and binary, and converts decimal numbers to hex.

Your numbers

Operation
Convert decimal to hex
Result in hex
1423

8AB + B78 = 1423 in hex (5,155 in decimal).

Result in decimal
5,155
Result in binary
1010000100011
First number in decimal
2,219
Second number in decimal
2,936

Result in hex: 1423. 8AB + B78 = 1423 in hex (5,155 in decimal).

How to calculate

Adds, subtracts, multiplies or divides two hexadecimal (base 16) whole numbers exactly at any size, shows the result in hex, decimal and binary, and converts decimal numbers to hex.

Example with the default inputs (First hex number 8AB, Operation +, Second hex number B78): 8AB + B78 = 1423 in hex (5,155 in decimal).

Method: Each hex number is read in base 16 (digit × 16ⁿ), the whole numbers are added, subtracted, multiplied or divided exactly, and the result is written back in base 16.

  • Numbers are whole (no hex fractions) and may be negative; a minus sign is written in front, not as two’s complement.
  • Division gives the whole-number quotient rounded toward zero and the remainder, A − quotient × B, which has the sign of A.
  • Numbers may have up to 100 characters; a 0x prefix, spaces, commas and underscores are ignored. Results use capital letters.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. First hex number 8AB, Operation +, Second hex number B78 gives Result in hex 1423, Result in decimal 5,155, First number in decimal 2,219, Second number in decimal 2,936, Result in binary 1010000100011.Source: Place values 16ⁿ (Wikipedia, "Hexadecimal", https://en.wikipedia.org/wiki/Hexadecimal)
  2. First hex number 8AB, Operation −, Second hex number B78 gives Result in hex -2CD, Result in decimal -717.
  3. First hex number FF, Operation ×, Second hex number 10 gives Result in hex FF0, Result in decimal 4,080.
  4. First hex number B78, Operation ÷, Second hex number 8AB gives Result in hex 1, Remainder (hex) 2CD, Result in decimal 1.
  5. First hex number -1A, Operation ÷, Second hex number 4 gives Result in hex -6, Remainder (hex) -2, Result in decimal -6.
  6. First hex number FFFFFFFFFFFFFFFF, Operation +, Second hex number 1 gives Result in hex 10000000000000000, Result in decimal 18446744073709551616.
  7. First hex number 8AB, Operation +, Second hex number B78, Decimal number to convert 48879 gives Decimal number in hex BEEF.

How it works

A hexadecimal (base 16) number uses the digits 0 to 9 and the letters A to F for 10 to 15. Each place is worth 16 times the place to its right:

value = Σ digit × 16ⁿ, where n counts places from 0 at the right

The calculator reads both numbers this way, does the arithmetic on the exact whole numbers, and writes the result back in base 16 (and in decimal and binary).

Rules and formats

  • A number may have up to 100 characters: an optional minus sign (-, − or –; a plus sign is not accepted), an optional 0x prefix, then hex digits. Spaces, commas and underscores are ignored. Letters may be capital or small. Anything else gives no answer: "The first number must be a hexadecimal number: the digits 0 to 9 and the letters A to F." (or "The second number …").
  • Addition, subtraction and multiplication are exact.
  • Division gives the whole-number quotient rounded toward zero, and the remainder A − quotient × B, which has the sign of A (so −1A ÷ 4 is −6 remainder −2). Dividing by 0 gives no answer: "The second number is 0, and you cannot divide by 0."
  • Results are written with capital letters and no 0x prefix; a negative result starts with a hyphen-minus (-2CD), not two’s complement. The binary result is written the same way (-1011).
  • The decimal box converts a whole decimal number (an optional sign, + or a minus sign as above, digits 0 to 9, up to 100 characters; spaces, commas and underscores are ignored) to hex. Anything else gives no answer: "The decimal number must be a whole decimal number: the digits 0 to 9."

Worked examples by hand

8AB + B78. From the right: B + 8 = 19 = 1 × 16 + 3, write 3 carry 1. A + 7 + 1 = 18 = 1 × 16 + 2, write 2 carry 1. 8 + B + 1 = 20 = 1 × 16 + 4, write 4 carry 1. Result: 1423. Check in decimal: 8AB = 2,219, B78 = 11 × 256 + 7 × 16 + 8 = 2,936, and 2,219 + 2,936 = 5,155 = 1 × 4,096 + 4 × 256 + 2 × 16 + 3. In binary: 1010000100011.

8AB − B78. 2,219 − 2,936 = −717, and 717 = 2 × 256 + 12 × 16 + 13 = 2CD, so the result is −2CD.

FF × 10. 255 × 16 = 4,080 = 15 × 256 + 15 × 16 = FF0. Multiplying by 10 in hex moves every digit one place left.

B78 ÷ 8AB. 2,936 = 1 × 2,219 + 717, so the quotient is 1 and the remainder is 717 = 2CD.

−1A ÷ 4. −26 ÷ 4 = −6.5, rounded toward zero to −6; the remainder is −26 − (−6 × 4) = −2.

FFFFFFFFFFFFFFFF + 1. 2⁶⁴ − 1 + 1 = 2⁶⁴ = 10000000000000000 in hex, 18,446,744,073,709,551,616 in decimal.

48,879 to hex. 48,879 = 11 × 4,096 + 14 × 256 + 14 × 16 + 15 = BEEF.

Other questions people ask

How do I add hex numbers?

Add column by column from the right, as in decimal, but carry when a column reaches 16. For 8AB + B78: B + 8 = 11 + 8 = 19 = 16 + 3, write 3 carry 1; A + 7 + 1 = 18 = 16 + 2, write 2 carry 1; 8 + B + 1 = 20 = 16 + 4, write 4 carry 1; so the sum is 1423.

How do I convert hex to decimal?

Multiply each digit by its place value, a power of 16, and add. The letters stand for 10 (A) to 15 (F). 8AB = 8 × 256 + 10 × 16 + 11 = 2,048 + 160 + 11 = 2,219.

How do I convert decimal to hex?

Divide by 16 again and again and read the remainders from the last to the first. 48,879 ÷ 16 = 3,054 remainder 15 (F); 3,054 ÷ 16 = 190 remainder 14 (E); 190 ÷ 16 = 11 remainder 14 (E); 11 is B. So 48,879 is BEEF. Use the Convert decimal to hex box.

How does hex division work here?

It is whole-number division: the quotient is rounded toward zero and the remainder is what is left, A − quotient × B. B78 ÷ 8AB is 1 remainder 2CD, because 2,936 = 1 × 2,219 + 717 and 717 is 2CD in hex.

How are negative results shown?

With a minus sign in front, such as −2CD for 8AB − B78. The calculator does not use two’s complement, which depends on a fixed number of bits.

How big can the numbers be?

Up to 100 characters each. The arithmetic uses exact whole numbers, so FFFFFFFFFFFFFFFF + 1 gives exactly 10000000000000000 (2⁶⁴), with no rounding.