Binary & Hex Arithmetic Calculator
Converting between bases is one job; doing arithmetic while staying in a base is another. This does the second, including the bitwise operations that only make sense in binary.
The Operation
Digits are checked against the base — a 2 in a binary number is rejected, not ignored.
Arithmetic is the same, only the carry changes
Addition in any base follows the same procedure you learned in decimal: add column by column and carry when a column reaches the base. In binary you carry at two, so 1 + 1 is 10; in hex you carry at sixteen, so F + 1 is 10. Nothing about the method changes, only the point at which the column overflows. Once that clicks, base conversion stops feeling like a separate skill.
Why hexadecimal and not something else
Sixteen is two to the fourth, so each hex digit maps to exactly four binary digits with no arithmetic needed: B is 1011, always, regardless of what surrounds it. That makes hex a compact shorthand for binary that a human can read aloud, which is why memory addresses, color codes and byte dumps all use it. Octal has the same property with three bits per digit and was common on older machines whose word sizes were multiples of three. Decimal has no such relationship to binary, which is why conversion between the two requires real division.
Bitwise operations are not arithmetic
AND, OR and XOR work on each bit position independently, with no carrying between columns. AND keeps a bit only where both inputs have it, which is how masks extract fields. OR sets a bit where either has it, which is how flags are combined. XOR sets a bit where exactly one has it, which makes it its own inverse — applying the same XOR twice returns the original value, the basis of the simplest possible cipher and of several neat swapping tricks. These operations have no meaningful decimal interpretation, which is why they belong on a page like this one.
Shifting is multiplication in disguise
Shifting left by one appends a zero, which doubles the value, exactly as appending a zero in decimal multiplies by ten. Shifting right by one discards the last bit and halves the value, rounding toward zero. Compilers use shifts in place of multiplication and division by powers of two because they are a single cheap instruction. The catch is that shifting left on a fixed-width type eventually pushes bits off the end and they are gone — this page uses arbitrary-precision integers so nothing is lost, which is deliberately different from how a 32-bit register behaves.
Why invalid digits are rejected
A 2 in a binary number, or a G in hex, is not a number in that base. Silently ignoring the bad character, or treating the input as decimal instead, produces a confident wrong answer. The parser here checks every character against the selected base and says which one it could not accept, because knowing the input was rejected is far more useful than receiving a plausible result derived from something you did not type.
Frequently Asked Questions
Why is hexadecimal used instead of decimal?
What is the difference between AND and addition?
Is shifting the same as multiplying?
Why was my input rejected?
Sources
Official publications only. Links open the original document in a new tab.
- National Institute of Standards and Technology Special Publication 811 — Guide for the use of the SI Significant figures and rounding conventions
- National Institute of Standards and Technology CODATA fundamental physical constants Values of the fundamental physical constants