$ man hex-calculator
Hex Calculator
NAME
hex-calculator — Add, subtract, multiply, divide, mask, shift and rotate hex values at 8, 16, 32 or 64 bits. Shows two's complement, the carry and overflow flags, and the exact value.
SYNOPSIS
# What is a hex calculator?
A hex calculator works out arithmetic and bitwise operations on hexadecimal numbers at a chosen word width, showing the answer as it would actually sit in an 8-, 16-, 32- or 64-bit register along with the carry and overflow flags.
WHY HERE
Number-base and data utilities for developers working with APIs.
| Flag | State | What it means |
|---|---|---|
| Carry / borrow | set | The unsigned answer did not fit the word; a bit was carried out of the top or borrowed into it. |
| Signed overflow | clear | The signed answer fitted the word. |
| Wrapped | yes | The exact answer is wider than the word, so what you see is the low bits of it. |
- 0xFF is 255 as an unsigned 8-bit value, and 0x01 is 1.
- Unsigned, 0xFF + 0x01 = 100, which does not fit in 8 bits — the top bit is carried out and lost, leaving 0x00.
- 255 + 1 = 0, which is 0x00.
Signed values are two's complement, which is what every current processor uses: in a byte, 0x80 is −128 and 0xFF is −1. Division truncates toward zero and the remainder takes the sign of the dividend, matching C, C++, Java, Rust and Go — Python floors instead, so −7 ÷ 2 is −3 here and −4 there. If your target language or device differs, check against its own specification before trusting a figure here.
// Integer operations only; fractional hex is a different job and belongs in a base converter. Signed results use two's complement with C-style truncating division, so a language that floors (Python) or a processor that traps on overflow will differ — check against your target's own specification before relying on a figure.
USAGE
01 → Set the word width before anything else
This is the setting that changes the answer. FF + 1 is 0x100 with no width and 0x00 with the carry flag set in a byte, and the second answer is the one a processor gives you.
02 → Say whether the top bit is a sign
Unsigned, a byte runs 0x00 to 0xFF. Signed, the same bits run −128 to 127 and 0xFF means −1. Nothing about the bits changes — only how they are read, and which flag matters.
03 → Enter shift and rotate amounts in decimal
A count of bit positions is not a hex value. "Shift left by 10" means ten places here, not sixteen, which is why the field changes its label and refuses hex digits for those operations.
04 → Read the flags, not just the number
Carry means the unsigned answer did not fit. Overflow means the signed answer has the wrong sign. They are different flags and they fire on different operations — 0x7F + 1 overflows without carrying, and 0xFF + 1 carries without overflowing.
05 → Check the exact row when something wrapped
The panel always shows the full-precision answer alongside the one that fits the word, so you can see exactly how much was lost rather than guessing.
DESCRIPTION
Hexadecimal is the notation people reach for when the individual bits matter: a register, a memory offset, a colour channel, a byte of a wire protocol. That is why a hex calculator that ignores word width is close to useless. FF + 1 is genuinely 0x100 in arithmetic, but in an 8-bit register it is 0x00 with the carry flag set, and in a uint8_t in C it is 0 with no warning at all. This calculator asks for the width first and reports both numbers, because the gap between them is where real bugs live.
Signed values use two's complement, the representation every processor made in the last fifty years uses. The top bit is not a separate sign flag — it is a digit worth minus two to the power of the width minus one, which is what makes the arithmetic work out: 0xFF read as a signed byte is −1 because 255 − 256 = −1, and adding 1 to it gives 0x00 with no special case anywhere in the hardware. It also explains the asymmetric range. A signed byte runs −128 to 127, not −127 to 127, because there is only one zero and the spare pattern goes to the negative side. That spare pattern is also the one division that overflows: the most negative value divided by −1 has no positive counterpart, and on x86 it raises a divide error rather than wrapping.
Carry and overflow are two different flags and confusing them is the most common mistake in this area. Carry says the unsigned answer did not fit the word — a bit fell out of the top on an add, or had to be borrowed in on a subtract. Overflow says the signed answer came out with the wrong sign: adding two positives gave a negative, or adding two negatives gave a positive. In a byte, 0xFF + 0x01 sets carry and not overflow; 0x7F + 0x01 sets overflow and not carry. Which one you care about depends entirely on whether the value is signed, and that is why this tool asks.
The shifts are worth separating too. A left shift multiplies by two to the power of the count and pushes the top bits off the end, where they are lost. A zero-filling right shift divides by a power of two and rounds down, and is what a C compiler emits for an unsigned type and what >>> does in Java and JavaScript. A sign-filling right shift copies the top bit into the vacated positions so a negative stays negative — and it rounds toward minus infinity rather than toward zero, so −7 >> 1 is −4 while −7 ÷ 2 truncates to −3. A rotate is a shift whose displaced bits come back in the other end, so nothing is ever lost and rotating by the full width returns the original value.
FAQ
## What is FF + 1 in hex?
0x100 if the number has no width. In an 8-bit register it is 0x00 with the carry flag set, because the 1 that would have gone in the ninth bit position has nowhere to go. In 16 bits it is 0x0100. The answer genuinely depends on the width, which is why this calculator asks for it.
## Why is 0xFF equal to −1?
Because in two's complement the top bit of a signed byte is worth −128 rather than +128. 0xFF is all eight bits set, which is −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1. The same bits read as unsigned are 255; nothing about the value in memory changes, only the interpretation.
## What is the difference between carry and overflow?
Carry is about unsigned arithmetic: a bit left the top of the word. Overflow is about signed arithmetic: the sign of the result is impossible for the operands. In a byte, 0xFF + 1 carries without overflowing, and 0x7F + 1 overflows without carrying.
## How does hex division handle remainders?
Division truncates toward zero and the remainder takes the sign of the dividend, which is what C, C++, Java, Rust, Go and every mainstream processor do. Both figures are shown. Python is the notable exception — it floors instead, so its answer for a negative dividend differs by one.
## Are the results exact for 64-bit values?
Yes. Everything runs on BigInt, so a 64-bit multiply is computed exactly and then reduced to the word, rather than going through a double and losing precision above 2^53 — which is where a calculator built on ordinary JavaScript numbers starts quietly rounding.