Math & ScienceFour bases

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.

RESULT
1100 0011
Binary1100 0011
Octal303
Decimal195
HexadecimalC3
Bits required8 bits
10110110 + 1101 in binary gives 1100 0011, which is 195 in decimal and C3 in hex. Addition carries when a column reaches the base — at 2 in binary, at 16 in hex. The method is identical to decimal; only the overflow point changes.

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?
Because sixteen is a power of two, so each hex digit maps to exactly four bits with no calculation. Decimal has no such relationship to binary, so conversion requires real division.
What is the difference between AND and addition?
AND works on each bit position independently with no carrying. Addition carries into the next column. Binary 1 AND 1 is 1, whereas binary 1 + 1 is 10.
Is shifting the same as multiplying?
Shifting left by one doubles the value and shifting right halves it, rounding toward zero. On fixed-width types a left shift can push bits off the end; this page uses arbitrary precision so nothing is lost.
Why was my input rejected?
It contained a digit that does not exist in the chosen base — a 2 in binary, or a letter beyond F in hex. The calculator names the offending character rather than guessing at what you meant.
Where these numbers come from

Sources

Official publications only. Links open the original document in a new tab.