About the Hex Calculator
This hex calculator does arithmetic directly in base 16. Enter two hexadecimal numbers — with or without a 0x prefix, in upper or lower case — choose add, subtract, multiply, divide or modulo, and get the answer in hexadecimal along with its decimal, binary and octal equivalents. Division returns the whole-number quotient and the remainder, the way integer division works in code.
It is useful for programmers calculating memory addresses and offsets, buffer sizes and pointer arithmetic, for reverse engineers and embedded developers reading register dumps, for web designers adjusting colour values, and for students checking base-16 homework. Numbers can be as large as you like: the calculator uses arbitrary-precision integers, so 64-bit and 128-bit values never lose digits.
Negative results are shown with a minus sign (for example −1A) rather than as a two’s-complement bit pattern; use the bitwise calculator if you need a fixed-width representation.
How to use the hex calculator
- 1Type the first hexadecimal number (a 0x prefix is optional).
- 2Choose add, subtract, multiply, divide or modulo.
- 3Type the second hexadecimal number.
- 4Read the hex result and its decimal, binary and octal equivalents.
- 5For division, check the remainder shown alongside the quotient.
Formula and method
Each hexadecimal digit stands for a power of 16: the rightmost digit counts ones, the next sixteens, then 256s, 4,096s and so on, with the letters A–F representing 10–15. The calculator converts both operands to exact integers, performs the operation, and converts the result back to base 16 (and to bases 10, 2 and 8). Because one hex digit is exactly four binary digits, the binary output is grouped in fours so each group lines up with one hex digit.
Division is integer division as in most programming languages: the quotient is truncated toward zero and the remainder has the same sign as the dividend, so a = quotient × b + remainder. Arbitrary-precision arithmetic means there is no overflow, whatever the size of the numbers.
- dᵢ
- Hex digit in position i (0 = rightmost)
- 16ⁱ
- Place value of that position
Worked examples
Adding 1A3F + FF
1A3F is 6,719 and FF is 255, so the sum is 6,974 = 1B3E. Column by column: F + F = 30 = 1E (write E, carry 1); 3 + F + 1 = 19 = 13 (write 3, carry 1); A + 1 = B; and the leading 1 stays, giving 1B3E.
Memory offset: 0x7FFF0000 − 0x1F400
Subtracting a 128,000-byte (0x1F400) region from 0x7FFF0000 (2,147,418,112) gives 0x7FFD0C00, or 2,147,290,112 in decimal.
Integer division with a remainder
FFFF is 65,535 and 1A is 26. 26 goes into 65,535 2,520 times (0x9D8) with 15 (0xF) left over, because 2,520 × 26 = 65,520 and 65,535 − 65,520 = 15.
Multiplying 64-bit values without overflow
(2³² − 1)² = 2⁶⁴ − 2³³ + 1, which is fffffffe00000001 in hex. The result needs all 16 hex digits of a 64-bit register, and the calculator keeps every digit exactly.
Frequently asked questions
How do you add hexadecimal numbers?+
Add column by column from the right, just like decimal, but carry when a column reaches 16 instead of 10. For example, F + 3 = 18 in decimal, which is 12 in hex: write 2 and carry 1 to the next column.
How do you subtract in hex?+
Subtract column by column from the right. When the top digit is smaller, borrow 1 from the next column, which adds 16 (not 10) to the current one. For example, 20 − 1 in hex: 0 − 1 borrows to make 16 − 1 = F, giving 1F.
What do the letters A–F mean in hex?+
Hexadecimal needs 16 digit symbols, so after 0–9 it uses A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Case does not matter: 1a3f and 1A3F are the same number.
What does the 0x prefix mean?+
0x marks a number as hexadecimal in C, C++, Java, JavaScript, Python and many other languages, so 0x10 means 16 rather than ten. Other notations include a trailing h (10h) in assembly and # for CSS colours.
Why do programmers use hexadecimal?+
One hex digit maps exactly to four binary bits and two digits to one byte, so hex is a compact, readable way to write binary data, memory addresses, colour codes, hashes and machine code without long strings of ones and zeros.