Hex Calculator: Add, Subtract, Multiply, Divide Hex
Add, subtract, multiply and divide hexadecimal numbers of any length, or apply AND, OR, XOR, NOT, shifts and rotations. Every result in hex, binary and decimal. Nothing is uploaded.
Enter values to see the result in binary, hex and decimal.
About the hex calculator
This page adds, subtracts, multiplies and divides hexadecimal numbers of any length and applies bitwise AND, OR, XOR, NAND, NOR, XNOR and NOT to them. Every result is shown in hex, binary and decimal, and each input shows its decimal value as you type, so you can check a memory address, a colour value or a register dump at a glance. Values may have up to 10,000 hex digits and the arithmetic is exact. Nothing is uploaded: the calculation runs in your browser.
How to calculate with hex
Steps
- The Hex system and the Add operation are selected. Pick another operation from the list if you need one.
- Type the first value (A) and the second value (B). Upper or lower case digits both work, and a
0xprefix, spaces and underscores are ignored. - Read the result in hex, binary and decimal, and press Copy next to the one you need.
- For a negative difference, set the Bit width to see the two's complement form a 16, 32 or 64-bit register would hold.
Worked examples
Addition and carries
FF + 1 is 100 in hex, which is 100000000 in binary and 256 in decimal. A carry out of a hex digit happens at 16 rather than at 10, which is the most common slip when adding hex by hand.
Subtraction
10 − 20 in hex is −10, minus sixteen. At 8 bits its two's complement is F0, the byte a program would store, and at 32 bits it is FFFFFFF0.
Multiplication and division
FF × FF is FE01, which is 255 × 255 = 65,025. Division gives a whole-number quotient and remainder: FF ÷ 10 is F remainder F.
Masks and flags
AND clears bits, OR sets them and XOR toggles them, which is how flags and masks are manipulated in code. ABCD AND 00FF keeps only the low byte, 00CD. With one-value operations, hex digits are the unit: rotating 1234 left by one digit gives 2341, reversing 12AB gives BA21, and Shuffle reorders the digits at random.
Why hexadecimal
Each hex digit stands for exactly four bits, so two digits make one byte and eight digits make a 32-bit word. That is why memory addresses, colour codes, hashes and machine registers are written in hex: it is short to read and converts to binary digit by digit.
Related tools
The Binary Calculator is the same tool with binary input. To convert hex to decimal, octal or any base from 2 to 36, use the Number Base Converter. To see the hex bytes of a piece of text, use Text to Hex.
Open-source credits
- The calculator is written for this site. Its arithmetic uses JavaScript's built-in arbitrary-precision BigInt type from the ECMAScript standard.
- Random values and shuffles use the browser's built-in Web Crypto API
crypto.getRandomValues. - The tool uses no third-party library.