Skip to content

Hex Calculator: Hexadecimal Arithmetic and Bitwise Operations

Add, subtract, multiply and divide hexadecimal numbers, and run AND, OR, XOR, NOT and bit shifts, with every result shown in hex, decimal, binary and octal.

3 min read

Hexadecimal, or hex, is base 16. Programmers use it because each hex digit stands for exactly four bits, so a byte is always two hex digits. You meet hex in colour codes, memory addresses, error codes, MAC addresses and file formats. Our hex calculator does arithmetic and bitwise operations directly in hex and shows each result in hex, decimal, binary and octal. This guide explains how hex arithmetic works.

How to use the calculator

  1. First number: a hex value, such as FF. Letters can be upper or lower case.
  2. Operation: +, −, ×, ÷, AND, OR, XOR, NOT (first number only), << or >>.
  3. Second number: another hex value.

The default, FF + 1A, gives 119 in hex, which is 281 in decimal and 100011001 in binary.

Hex digits

Hex uses sixteen symbols: 0 to 9, then A to F for ten to fifteen.

HexDecimalBinary
991001
A101010
B111011
C121100
D131101
E141110
F151111
101610000
FF25511111111

Each position is worth a power of 16: 1, 16, 256, 4,096 and so on. So 1A = 1 × 16 + 10 = 26, and FF = 15 × 16 + 15 = 255.

Hex addition

Add digit by digit from the right. Whenever a column reaches 16 or more, subtract 16 and carry 1.

FF + 1A:

  1. F + A = 15 + 10 = 25. 25 − 16 = 9, carry 1.
  2. F + 1 + carry 1 = 17. 17 − 16 = 1, carry 1.
  3. Bring down the carry: 1.

Result: 119. Check in decimal: 255 + 26 = 281, and 1 × 256 + 1 × 16 + 9 = 281.

Subtraction, multiplication and division

Subtraction borrows 16 instead of 10. 1F4 − FF = F5 (500 − 255 = 245).

Multiplication by 10 in hex shifts left one digit, just as multiplying by 10 does in decimal. FF × 10 = FF0 (255 × 16 = 4,080). Other products are easiest to check in decimal.

Division gives a whole-number quotient and a remainder.

Bitwise operations in hex

Bitwise operations work on the underlying bits, and hex makes the patterns easy to read because each digit is four bits.

  • AND with a mask keeps selected bits. Colour code 0x3366CC AND 0x00FF00 = 0x006600, isolating the green channel.
  • OR sets bits: 0x0F OR 0xF0 = 0xFF.
  • XOR flips bits where the mask has 1s: 0xFF XOR 0x0F = 0xF0.
  • NOT inverts every bit.
  • Shifts move bits left or right; shifting left by 4 bits moves a value up one hex digit.

The binary calculator shows the same operations bit by bit.

Where you meet hex

  • Web colours: #RRGGBB, where each pair is 00 to FF. #FF8800 is red 255, green 136, blue 0, an orange.
  • Memory addresses and debugging: pointers and crash dumps are written in hex, often with a 0x prefix.
  • Network hardware: MAC addresses such as 00:1A:2B:3C:4D:5E are six hex bytes. IPv6 addresses are written in hex too. The IP subnet calculator covers IPv4 masks.
  • Character codes: Unicode code points are written like U+00E9 (é).
  • Error codes and hashes: checksums such as SHA-256 are long hex strings.

Converting quickly

To convert hex to decimal, multiply each digit by its power of 16 and add. To go from decimal to hex, divide repeatedly by 16 and read the remainders upward. The binary and hex converter does both instantly, and the base64 encoder handles another common encoding for binary data.

Tips

  • Prefix hex values with 0x in code to avoid confusion with decimal: 0x10 is 16, not 10.
  • Group long hex strings in pairs (bytes) or fours (16-bit words) to read them.
  • Leading zeros do not change the value, but they matter for fixed-width fields like colours.

Frequently asked questions

Why do programmers use hexadecimal?

It is a compact, readable form of binary. Each hex digit is exactly four bits, so converting between the two is simple.

What does 0x mean?

It is a prefix marking a number as hexadecimal, used in most programming languages. 0xFF means hex FF, which is 255.

Is hex case-sensitive?

No. FF, ff and Ff all mean the same value.

How do I convert a colour code to RGB?

Split it into three pairs and convert each to decimal. #3366CC is 51, 102 and 204.

Share

Try it yourself

Run your own numbers with our free tool: Hex calculator. No sign-up, and it works on any device.

Open the calculator