Hex Calculator
Do arithmetic in hexadecimal. Type the digits 0 to 9 and A to F, press an operation, and read the answer in hex, decimal, octal and binary.
https://flxcode.com/hex-calculator/
- T
- 0
- Z
- 0
- Y
- 0
Type with the keyboard or the keys below, or paste a number. Click a row to type in that base.
Bits (click one to flip it)
Try an example
History (this visit only)
Nothing yet. Results appear here, newest first.
Keyboard shortcuts
| 0–9, A–F | type digits (digits outside the input base are refused) |
|---|---|
| + − * / % | add, subtract, multiply, divide, modulo |
| & | ^ ~ | AND, OR, XOR, NOT |
| q w | NAND, NOR |
| < > s | shift left, shift right (logical), shift right (arithmetic) |
| r Shift+R | rotate left, rotate right |
| n | change sign |
| Enter or = | equals (ENTER in RPN mode) |
| Backspace | delete the last digit |
| Esc | clear the number; press again to clear everything |
| x k Delete | RPN: swap X and Y, roll the stack down, drop X |
No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.
Problem or idea? Email us
Quick start
- HEX is already the input row. Type the first number with the keypad or the keyboard.
- Press +, −, × or ÷, then type the second number and press =.
- Read the answer in the HEX row, or in DEC if you want the decimal value.
- If a flag line appears, the answer was cut to the word size. Choose a larger word to keep every bit.
Worked examples
| Sum | Word | Hex result | Decimal result | Flag | Why |
|---|---|---|---|---|---|
| FF + 1 | 8-bit unsigned | 00 | 0 | carry | One byte is full. The sum needs a ninth bit, so the byte wraps to 00 with carry. |
| 7FFF + 1 | 16-bit signed | 8000 | -32768 | overflow | The largest signed 16-bit number plus one flips the sign bit: overflow. |
| 7FFFFFFF + 1 | 32-bit signed | 80000000 | -2147483648 | overflow | The same thing at 32 bits. |
| DEADBEEF − BEEF | 32-bit unsigned | DEAD0000 | 3735879680 | none | Clearing the low half of a famous marker. |
| 1000 − 1 | 16-bit unsigned | 0FFF | 4095 | none | Borrowing runs through every zero digit. |
| 0 − 1 | 16-bit unsigned | FFFF | 65535 | carry | Below zero wraps to the top, with borrow. |
| FF × FF | 16-bit unsigned | FE01 | 65025 | none | 255 × 255 = 65025 fits in 16 bits. |
| FF × FF | 8-bit unsigned | 01 | 1 | carry | The same product in 8 bits keeps only the low byte, with carry. |
| 100 ÷ 30 | 32-bit unsigned | 00000005 | 5, remainder 16 | none | 256 ÷ 48 is 5 remainder 16, written here in decimal. |
The six extra digits
A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Everything else is as in decimal, except that a column holds up to 15 before it carries.
Adding by hand
2B7 + 19C, working from the right. A column that reaches 16 or more writes its remainder and carries 1.
| Column | Top | Bottom | Carry in | Total (decimal) | Write | Carry out |
|---|---|---|---|---|---|---|
| 1 | 7 | C | 0 | 19 | 3 | 1 |
| 2 | B | 9 | 1 | 21 | 5 | 1 |
| 3 | 2 | 1 | 1 | 4 | 4 | 0 |
The answer is 453.
Subtracting by hand
5A2 - 1F7. When the top digit is too small, borrow 1 from the next column, which adds 16 here.
| Column | Top | Borrowed in | Top after | Bottom | Write | Borrow out |
|---|---|---|---|---|---|---|
| 1 | 2 | 0 | 18 | 7 | B | 1 |
| 2 | A | 1 | 25 | F | A | 1 |
| 3 | 5 | 1 | 4 | 1 | 3 | 0 |
The answer is 3AB.
When the answer wraps
A register holds a fixed number of bits, so every result is cut to that width. Hex makes the cut easy to see: at 16 bits, the result keeps its last four hex digits. FFFF + 1 is 10000 on paper and 0000 in the register, with the carry set. The flag line under the screen says which of the two flags applies. Carry is for unsigned numbers, overflow is for signed ones.
Where hex arithmetic turns up
- Memory addresses: a base address plus an offset, as in 0x4000 + 0x1C.
- Colour values: adding to a channel such as 0x80 + 0x40 without running past 0xFF.
- Masks and sizes: 0x1000 - 1 is the mask 0xFFF for a 4 KiB page.
- Hex dumps and checksums: adding bytes and keeping only the low byte.
To convert a value without doing arithmetic use hex to decimal or hex to binary. For shifts, rotates and bit masks open the programmer calculator.
Numbers this uses
- Hex digits 0 to 9 and A to F. Case does not matter when pasting.
- Word sizes 8, 16, 32 and 64 bits, exact integers (BigInt).
- Division is integer division that rounds toward zero. The remainder is shown beside the quotient.
Nothing you type is uploaded. We count events without cookies (details).
FAQ
How do I add hex numbers?
Add column by column from the right, like decimal, but a column carries when it reaches 16 instead of 10. 7 + C is 19 in decimal, which is 13 in hex: write 3 and carry 1. The worked column table above does 2B7 + 19C step by step.
How do I subtract in hex?
Subtract column by column. When the top digit is smaller than the bottom digit, borrow 1 from the next column. That adds 16 to the column you are working on, not 10. The column table above shows 5A2 - 1F7 with the borrows.
What does it mean when the result wraps?
The calculator works in a fixed width, like a processor register. FF + 1 needs nine bits, but an 8-bit register holds eight, so the extra bit is dropped and the result is 00. The carry flag tells you it happened. Choose 32 or 64 bits if you want room for bigger sums.
Which word size should I pick?
Use the size of the value you are working with: 8 bits for a byte or a register on a small chip, 16 for a short, 32 for an int on most platforms and an IPv4 address, 64 for a pointer on a modern PC. This page starts at 32.
Can the calculator handle negative hex numbers?
Yes, in signed mode. FFFF at 16 bits is -1 there, and FFFE is -2. You can also type -1 in decimal and read FFFF in the HEX row. Hex numbers do not have a minus sign inside the word. They are bit patterns.
Do I type 0x in front?
No need. With the HEX row selected the keys 0 to 9 and A to F are all you need. If you paste a number that starts with 0x or $ it is read as hex anyway. Underscores and spaces in a pasted number are ignored.
Why does the examples table show decimal next to hex?
So you can check each sum with ordinary numbers. In the calculator the remainder of a division is shown in the input base, so it is in hex while the HEX row is selected. Click DEC to read it in decimal.
Is anything I type saved or sent?
No. The calculator runs in your browser. What you type is not put in the address bar, not stored and not counted. Your last word size and base are remembered on this device, and nothing else.
More from FLXCode
Programmer CalculatorNew
Hex, decimal, octal and binary at once with 8 to 64-bit words, AND, OR, XOR, shifts, rotates, a bit grid and RPN.
Number Base ConverterNew
Convert any number between bases 2 and 36, exact with BigInt. Negative and fractional input, bits grouped by 4.
Hex to Decimal ConverterNew
Turn hexadecimal into decimal, with the place values worked out. Also binary, octal and bases up to 36.
Long Division CalculatorNew
Long division laid out like on paper, with the remainder and the decimal, repeating part marked.