Skip to content

Hex Calculator

Convert whole numbers between hexadecimal (base 16) and decimal, or add, subtract, multiply and divide hex numbers. Results also show the binary form, and division gives the remainder.

Mode
Convert from

Hex uses 0–9 and A–F, and is not case-sensitive. Decimal numbers may start with a minus sign.

Hexadecimal

FF

255 in decimal is FF in hexadecimal. Divide by 16, keep each remainder, and read the remainders from the bottom up. Remainders of 10 to 15 are written A to F.

Hexadecimal
FF
Decimal
255
Binary
11111111

How to use this calculator

  1. 1 Pick Convert to change one number between decimal and hexadecimal. Then choose which base you are starting from.
  2. 2 Pick Arithmetic to work with two hex numbers. Use 0–9 and A–F. Upper or lower case both work.
  3. 3 Choose an operation. For division, the whole-number quotient is the result, and the remainder is shown below it.

What is hexadecimal?

Hexadecimal, or hex, is a number system with 16 digits. The digits are 0 to 9, then A to F. A stands for 10, B for 11, and so on up to F, which stands for 15.

Each place in a hex number is worth 16 times the place to its right. So the places are worth 1, 16, 256, 4,096 and so on. The full name mixes Greek for six with Latin for ten, and it is often shortened to hex.

Hex is popular with programmers because 16 is a power of 2. One hex digit stands for exactly four binary digits, which makes long binary values much shorter.

Reading a hex number

To read a hex number, multiply each digit by its place value and add the results. Remember that A to F stand for 10 to 15. So the number 1F4 is 1 × 256 + 15 × 16 + 4 × 1.

That adds up to 256 + 240 + 4 = 500. The calculator shows the same working in its results.

Reading 1F4 in hexadecimal
Place value256161
Hex digit1F (15)4
Value2562404

Converting decimal to hexadecimal

To change a decimal number into hex, divide by 16 and keep each remainder. Keep dividing the result by 16 until you reach 0. Then read the remainders from the bottom up, writing 10 to 15 as A to F.

Take 500. Dividing 500 by 16 gives 31 remainder 4. Then 31 ÷ 16 = 1 remainder 15, which is F. Finally 1 ÷ 16 = 0 remainder 1. Reading from the bottom gives 1F4.

The binary calculator uses the same method with 2 instead of 16. It is a good place to see how the bases compare.

Hex arithmetic

Hex arithmetic works like decimal arithmetic, but you carry at 16 instead of 10. For example, FF + 1A is 255 + 26 = 281, which is 119 in hex.

Other examples show the same idea. FF × 2 is 510 in decimal, which is 1FE in hex. And 100 − 1 is 256 − 1 = 255, which is FF.

Division gives a whole-number quotient and a remainder, just like long division. In decimal, the remainder is always smaller than the divisor, and the same is true in hex. For the method on paper, see the long division calculator. To check decimal sums, the basic calculator helps.

Why hex is used in computing

Computers store data in bytes, and one byte is eight bits. Two hex digits can show exactly one byte, so a value from 00 to FF covers every possible byte. That is much easier to read than eight 0s and 1s.

Hex is common in web colour codes. The code #FF0000 means full red, with FF for red, 00 for green and 00 for blue. Memory addresses and error codes are often written in hex too.

To change hex to binary, write each hex digit as its four-bit binary form. For example, F is 1111 and 4 is 0100, so 1F4 is 0001 1111 0100.

The formula

Hexadecimal to decimal

value = dₙ×16ⁿ + … + d₁×16¹ + d₀×16⁰

dₖ
the digit in position k, counting from the right starting at 0. A to F stand for 10 to 15
16ᵏ
the place value of that position: 1, 16, 256, 4096 and so on

Decimal to hexadecimal

Divide by 16 and keep the remainder. Repeat on the quotient until it is 0, then read the remainders from last to first.

r
each remainder is 0 to 15, written as one hex digit (0–9, then A–F)

Division with remainder

a = q × b + r, where 0 ≤ r < b

q
the quotient: the whole number of times b fits into a
r
the remainder left over

Worked example

Add FF and 1A in hexadecimal

  1. 1.FF in decimal is 15×16 + 15 = 255.
  2. 2.1A in decimal is 1×16 + 10 = 26.
  3. 3.255 + 26 = 281.
  4. 4.281 in hexadecimal is 119, because 1×256 + 1×16 + 9 = 281.

FF + 1A = 119 in hexadecimal, which is 281 in decimal.

Frequently asked questions

What does hexadecimal use for digits above 9?

It uses the letters A to F for the values 10 to 15. A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15. Case does not matter, so ff and FF are the same number.

Why is hexadecimal used in computing?

One hex digit stands for exactly four binary digits, so a byte (eight bits) fits in two hex digits. That makes long binary values, such as memory addresses and colour codes, shorter and easier to read.

How do I convert decimal to hexadecimal by hand?

Divide the number by 16 and write down the remainder, using A to F for 10 to 15. Repeat on the quotient until it reaches 0, then read the remainders from the last to the first.

Why does the calculator reject the 0x prefix?

The prefix 0x is a programming convention, and the letter x is not a hex digit. Type the digits alone, such as 1F4 instead of 0x1F4.

Sources

Last reviewed by the GridCalculators team.