Skip to content

Hexadecimal Calculator: Hex Arithmetic and AND, OR, XOR

Add, subtract, multiply, divide or AND/OR/XOR two hex numbers exactly, with the result in hex, decimal and binary.

Your details

Digits 0–9 and A–F, up to 64 digits. A minus sign and a 0x prefix are allowed.

Type any whole decimal number to see it in hexadecimal and binary.

Results update as you type

Result (hex)

1AF6

Result in decimal
6,902
Result in binary
1 1010 1111 0110
A and B in decimal
A = 6,719, B = 183
Hex digits in the result
4

Step-by-step solution
  1. 1A3F + B7 = 1AF6
  2. Whenever a column total reaches 16 or more, write total − 16 and carry 1 to the next column.
  3. In decimal: 6,719 + 183 = 6,902

Column addition in base 16 (position 0 = rightmost digit)

Hexadecimal (base 16) writes numbers with sixteen symbols: the digits 0–9 followed by the letters A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Programmers use it everywhere — memory addresses, colour codes such as #FF8800, Unicode code points, checksums and machine registers — because each hex digit stands for exactly four bits. Two hex digits make one byte, so 0xFF is 255 and 0xFFFF is 65,535.

This hexadecimal calculator performs addition, subtraction, multiplication and division (whole quotient plus remainder) on two hex numbers, as well as the bitwise operations AND, OR and XOR that are so common in low-level code. It uses exact big-integer arithmetic, so numbers up to 64 hex digits (256 bits) are handled without rounding — far beyond what a typical pocket calculator or spreadsheet can do.

Every result is shown in hexadecimal, decimal and binary at once. Additions and subtractions come with a column-by-column table of carries and borrows, multiplications with their partial products, and divisions with the check A=B×Q+RA = B \times Q + R. The optional converter row turns any decimal integer into hex and binary, which is handy when you need to cross-check a value from documentation or a debugger. To work purely with base 2, see the binary calculator.

How to use this calculator

  1. Type the first hexadecimal number A, for example 1A3F. Upper or lower case both work; a 0x prefix, spaces and underscores are ignored.
  2. Choose the operation: +, −, ×, ÷, AND, OR or XOR.
  3. Type the second number B, for example B7.
  4. Read the result in hex at the top, then in decimal and binary. Open the steps and the table to follow every carry, borrow or partial product.
  5. Optionally, type a decimal number in the converter field to see its hexadecimal and binary form.

The formula

A hexadecimal numeral hn−1…h1h0h_{n-1}\ldots h_1 h_0 stands for

N=∑i=0n−1hi⋅16i,hi∈{0,1,…,9,A,B,C,D,E,F}N = \sum_{i=0}^{n-1} h_i \cdot 16^{i}, \qquad h_i \in \{0, 1, \ldots, 9, A, B, C, D, E, F\}

Addition works column by column from the right: the result digit is (ai+bi+ci) mod 16(a_i + b_i + c_i) \bmod 16 and the carry is ci+1=⌊(ai+bi+ci)/16⌋c_{i+1} = \lfloor (a_i + b_i + c_i) / 16 \rfloor, which is 0 or 1.

Subtraction borrows 16 from the next column whenever ai−bi−ki<0a_i - b_i - k_i < 0.

Multiplication adds one shifted partial product per digit of BB: A×B=∑i(A×hi)⋅16iA \times B = \sum_i (A \times h_i) \cdot 16^{i}, and a shift by one hex place multiplies by 16.

Division finds the quotient QQ and remainder RR with A=B×Q+RA = B \times Q + R and ∣R∣<∣B∣|R| < |B|.

Bitwise operations compare the binary expansions bit by bit: AND gives 1 only where both bits are 1, OR where at least one is 1, XOR where exactly one is 1. Because 16=2416 = 2^4, each hex digit maps to a group of four bits, for example B=1011\mathrm{B} = 1011 and 7=0111\mathrm{7} = 0111.

Worked example

Take A=1A3F16=6,719A = \mathrm{1A3F}_{16} = 6,719 and B=B716=183B = \mathrm{B7}_{16} = 183.

Addition. From the right: F+7=22=16+6F + 7 = 22 = 16 + 6, write 6 carry 1; 3+B+1=153 + B + 1 = 15, write F; A+0=10A + 0 = 10, write A; then 1. The carries read 0001 and the sum is 1AF6 (6,902 in decimal).

Subtraction. 1A3F−B7\mathrm{1A3F} - \mathrm{B7} = 1988 (6,536); the second column needs a borrow because 3 is smaller than B. Reversing the order gives −1988, the same magnitude with a minus sign.

Multiplication. 1A3F×B7\mathrm{1A3F} \times \mathrm{B7} = 12C309 (1,229,577).

Division. 1A3F÷B7\mathrm{1A3F} \div \mathrm{B7} gives quotient 24 and remainder 83, that is 36 remainder 131 in decimal.

Bitwise. 1A3F AND B7 = 37, 1A3F OR B7 = 1ABF, 1A3F XOR B7 = 1A88.

Hex digits, bits and bytes

The table below is the key to doing hexadecimal arithmetic in your head. Each hex digit corresponds to one four-bit pattern (a nibble), so converting between hex and binary never needs any arithmetic — just replace each digit by its four bits.

Hex Decimal Binary Hex Decimal Binary
0 0 0000 8 8 1000
1 1 0001 9 9 1001
2 2 0010 A 10 1010
3 3 0011 B 11 1011
4 4 0100 C 12 1100
5 5 0101 D 13 1101
6 6 0110 E 14 1110
7 7 0111 F 15 1111

For conversions between any bases (2 to 36, including octal) use the number base converter.

Where AND, OR and XOR are used

Bitwise operations are the everyday tools of systems programming. AND with a mask keeps selected bits: colour AND FF extracts the blue byte of a 24-bit RGB colour, and x AND F returns the last hex digit. OR sets bits, for example to switch on a flag in a status register. XOR flips bits; applying the same XOR twice restores the original value, which is why it appears in checksums, simple ciphers and parity calculations.

Negative numbers are usually stored in two’s complement, and the result of a bitwise operation on them depends on the register width. To keep results unambiguous, this calculator applies AND, OR and XOR to non-negative values only; the four arithmetic operations accept negative numbers written with a minus sign.

Frequently asked questions

How do you add hexadecimal numbers?

Line the numbers up on the right and add each column in decimal. If the column total is 16 or more, write the total minus 16 as a hex digit and carry 1. For example F + 7 = 22, which is 16 + 6: write 6 and carry 1. 1A3F + B7 = 1AF6.

What do the letters A to F mean in hexadecimal?

They are single digits for the values ten to fifteen: A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Base 16 needs sixteen distinct symbols, and the letters fill the gap after 9.

How do I convert a decimal number to hex?

Divide by 16 repeatedly and write the remainders from last to first. 255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15, so 255 = FF. The converter field of this calculator does it instantly for integers of any size.

How does hexadecimal division handle the remainder?

The calculator returns a whole-number quotient and a remainder such that A = B × Q + R. For 1A3F ÷ B7 the quotient is 24 and the remainder 83 (6719 = 183 × 36 + 131 in decimal). Division by zero is reported as an error.

What is XOR in hex?

XOR (exclusive or) compares the two numbers bit by bit and gives 1 where the bits differ. Convert each hex digit to four bits, XOR them, and convert back: B XOR 7 = 1011 XOR 0111 = 1100 = C.

Sources

Last updated:

More Math calculators

People also use