Binary Calculator
Developer Tools · Added
Two values, one operation, and a word size that actually matters. This computes arithmetic and every bitwise operation on fixed-width integers from 8 to 64 bits, shows both operands and the result as bit patterns, and reports overflow rather than hiding it — so when 200 plus 100 comes out as 44 in a byte, you can see exactly why. It is built on arbitrary-precision integers underneath, so 64-bit values behave correctly rather than being silently truncated to 32.
How to use the binary calculator
- 1Choose the base your values are written in — binary, octal, decimal or hexadecimal.
- 2Pick the word size. Results wrap to this width, which is what a real processor does.
- 3Choose the operation: arithmetic, a bitwise logic operation, or a shift.
- 4Enter the two values; for a shift, the second box is the number of places.
- 5Turn on signed mode to read the values as two's complement, where the top bit means negative.
Examples
Masking with AND
- Input
- 1010 & 0110 in binary
- Result
- 0010 — only the bit set in both survives
The most common use of AND is testing or clearing specific bits with a mask.
A shift as a multiplication
- Input
- 1 << 4 in decimal
- Result
- 16
Each place shifted left doubles the value, so shifting by four multiplies by sixteen.
Overflow in a byte
- Input
- 200 + 100, 8-bit unsigned
- Result
- 44 — with the true result of 300 reported alongside
The high bit is discarded because it does not fit. This is where a whole category of security bugs comes from.
About the binary calculator
What the bitwise operations are actually for
AND with a mask tests or clears bits. `flags & 0x04` is non-zero exactly when the third bit is set, which is how a status register is read; `flags & ~0x04` clears that bit and leaves the rest alone. OR sets bits: `flags | 0x04` turns the third bit on regardless of what it was. Together they are how a single integer stores a dozen independent yes-or-no settings, which is why they turn up in every file permission, every graphics API and every network protocol header.
XOR is the interesting one. It flips exactly the bits set in the mask, and applying the same XOR twice returns the original — which makes it the basis of the simplest possible cipher, a fast way to swap two variables without a temporary, and the mechanism behind parity and checksum calculations. It also detects difference: `a ^ b` is zero exactly when the two are equal.
Shifts are multiplication and division by powers of two, and historically that was their point — a shift is a single fast instruction where a multiply was many. Compilers now do that substitution themselves, so writing `x << 3` instead of `x * 8` no longer buys speed and does cost readability. Where shifts remain the clear expression is in packing and unpacking fields: extracting the red channel from a 24-bit colour is `(rgb >> 16) & 0xFF`, and no arithmetic phrasing is clearer.
Overflow, and why it is worth seeing
When a result does not fit the word, the bits above the top are discarded and what remains is the answer modulo the word size. For unsigned arithmetic that wraps to zero; for signed arithmetic it wraps from the largest positive value to the most negative, which is the more surprising case — adding 1 to a 32-bit signed 2147483647 gives −2147483648.
This is not a rare edge case, it is a major category of software defect. A length check that adds two sizes and compares the result can be defeated by making the sum overflow to something small. A counter that wraps can cause a loop to run for far longer than intended, or not at all. The Ariane 5 launch failure in 1996 came from a 64-bit float being converted to a 16-bit signed integer that could not hold it.
The reason this page reports the true result alongside the wrapped one is that seeing both is what makes the behaviour intelligible. A calculator that quietly returns 44 for 200 plus 100 is technically correct for an 8-bit word and teaches nothing; showing that the real answer was 300 and that 256 of it was discarded shows exactly where the missing value went.
Frequently asked questions
Why does the word size change the answer?
What is two's complement, and why is 11111111 equal to −1?
What is the difference between the two right shifts?
Why not just use JavaScript's bitwise operators?
Why is shifting by more than the word size refused?
Related tools
Number Base Converter
Converters
Convert between binary, octal, decimal, hexadecimal and any base from 2 to 36.
ASCII Table
Developer Tools
Searchable ASCII reference with decimal, hex, octal, binary and escapes.
Chmod Calculator
Developer Tools
Convert Unix file permissions between the octal number, the symbolic string and a tick-box grid.