Hex Calculator

Type two hexadecimal numbers, choose + − × ÷ and read the answer in hex, decimal, binary and octal. Further down you can change any hex number to decimal or any decimal number to hex, and see the table that explains each conversion.

How it is calculated

Type the first hex number.

Choose the operation.

Type the second hex number.

Read the result in hex, decimal, binary and octal.

Formula

Digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F (A = 10 … F = 15)

Place values: … 16³ = 4096, 16² = 256, 16¹ = 16, 16⁰ = 1

Hex to decimal: Multiply each digit by its place value and add

Decimal to hex: Divide by 16 again and again; read the remainders from last to first

What is the Hex Calculator?

A hex calculator does arithmetic on hexadecimal numbers. Hexadecimal is the base 16 number system, which uses the sixteen digits 0 to 9 and A to F. With this tool you can add, subtract, multiply and divide two hex numbers directly, without first changing them to ordinary decimal numbers on paper.

It also converts in both directions between hex and decimal and shows the working, so it is useful for learning as well as for checking answers. Students of computer science meet hex in the number systems chapter, and anyone who writes code or designs web pages sees it in colour codes and memory addresses. The answer is shown in binary and octal as well, so you can compare all four systems side by side.

How to calculate it by hand

1. Write the two hex numbers one below the other, lined up from the right.

2. Remember the letter values: A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.

3. Work column by column from the right, as in ordinary sums.

4. In addition, if a column total is 16 or more, subtract 16 and carry 1.

5. In subtraction, a borrowed 1 is worth 16, not 10.

6. Write each column answer as a hex digit, using letters for 10 to 15.

Sixteen digits and powers of sixteen

In decimal, each place is worth ten times the one on its right. In hex, each place is worth sixteen times as much: ones, sixteens, two hundred and fifty-sixes, and so on. Since one place needs to hold values up to fifteen, six extra symbols are borrowed from the alphabet. The number 5DC therefore means 5 × 256 + 13 × 16 + 12, which comes to 1500 in decimal.

Why hex and binary fit together

Sixteen is two multiplied by itself four times. Because of this, every hex digit matches exactly four binary digits: 0 is 0000, 9 is 1001 and F is 1111. To change binary to hex you cut the binary number into groups of four from the right and replace each group with one hex digit. A byte of eight bits always becomes exactly two hex digits, which is why hex is the favourite shorthand of programmers.

Carrying and borrowing in base sixteen

The method for sums is the same as in decimal; only the carrying point changes. In addition, a column that reaches sixteen sends 1 to the next column. For example, B + 8 is 11 + 8 = 19, which is 16 + 3, so you write 3 and carry 1. In subtraction, when the top digit is too small you borrow 1 from the next column, and that 1 adds sixteen to the present column.

Worked example, step by step

In her computer lab in Hyderabad, Lakshmi has to add the memory offset 1F4 to the base address 2C0 and write the new address in hex.

Change the first number to decimal: 2C0 = (2 × 256) + (12 × 16) + (0 × 1) = 704

Change the second number to decimal: 1F4 = (1 × 256) + (15 × 16) + (4 × 1) = 500

Do the sum in decimal: 704 + 500 = 1204

Write the answer back in hex: 1204 = 4B4

Answer: Result in hex 4B4; In decimal 1204; In binary 0100 1011 0100

Common mistakes to avoid

Carrying at 10 as in decimal instead of at 16.

Treating a borrowed 1 as ten instead of sixteen.

Reading the hex number 10 as ten. It is sixteen.

Mixing up the letter values, for example taking B as 12.

Reading the remainders from top to bottom when converting decimal to hex.

Where it is used

Number system chapters in school and college computer science.

Reading and adjusting colour codes such as #FF9933.

Working with memory addresses while programming.

Checking MAC addresses and other network values.

Debugging data shown in a hex dump.

Frequently asked questions

How do I add two hex numbers by hand?

Add column by column from the right, as in ordinary addition. Whenever a column total reaches 16 or more, subtract 16, write what is left and carry 1 to the next column.

How do I convert hex to decimal?

Multiply each digit by its place value (1, 16, 256 …) and add the results. For DAD: 13 × 256 + 10 × 16 + 13 = 3501.

How do I convert decimal to hex?

Divide the number by 16 and note the remainder. Keep dividing the quotient until it becomes 0. The remainders read from last to first give the hex number. 170 becomes AA.

Where is hex used?

In colour codes on web pages such as #FF9933, in memory addresses, in MAC addresses of network devices and whenever programmers need a short form of binary.

Does it matter if I type small letters?

No. ff and FF mean the same number.