Bitwise Calculator
Apply AND, OR, XOR or shifts to two integers.
What it does
Bitwise operators work directly on the binary digits of integers. They are used for masking, packing flags, fast arithmetic by powers of two and many low level algorithms.
University of Alaska Fairbanks computer science notes describe AND as a mask, OR as reassembling bit fields, XOR as controlled inversion and shifts as moving bits to higher or lower places.
The page gives small examples such as 3 AND 5 equals 1, which corresponds to 0011 AND 0101 equals 0001.
This tool applies one chosen operation to two nonnegative integers and shows the result in decimal and binary, together with both operands in binary.
The operations use 32 bit unsigned arithmetic, which matches the usual behaviour for these operators in many languages.
How to use
- Enter two nonnegative whole numbers.
- Choose AND, OR, XOR, left shift or right shift.
- For shifts, set the shift amount.
- Read the decimal and binary results.
- Check both operands in binary to follow the operation bitwise.
- Try 12 and 10 with AND to get 8.
Formula
- a, b
- The two integer operands.
- n
- Shift amount for shift operations.
- bit
- A single binary digit, 0 or 1.
- mask
- Using AND with zeros to clear unwanted bits.
The engine coerces results to unsigned 32 bit values. It rejects negative operands and fractional inputs rather than applying language specific conversions.
Worked example
Example: masking with AND
Operands 12 and 10 with the AND operation.
- 12 in binary is 1100 and 10 in binary is 1010.
- Comparing bit by bit, only the third bit is set in both.
- The result is 1000 in binary, which is 8 in decimal.
- The tool reports result 8 and binary 1000.
- Using OR instead gives 1110, or 14.
- Using XOR gives 0110, or 6.
Reference table
| Operation | Binary | Decimal |
|---|---|---|
| AND | 1000 | 8 |
| OR | 1110 | 14 |
| XOR | 0110 | 6 |
| Left shift 12 by 2 | 110000 | 48 |
Limits
- Operands are limited to 0 through 4294967295.
- Shifts use up to 31 positions.
- The tool uses 32 bit unsigned arithmetic.
- It handles integers only, not floating point bit patterns.
Common mistakes
- Entering negative numbers and expecting two's complement behaviour.
- Using the second operand for a shift when only the first is shifted.
- Confusing XOR with OR when both bits are set.
- Expecting right shift to preserve sign, which unsigned arithmetic does not.
- Forgetting that a shift amount of zero changes nothing.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is 12 AND 10?
8, because 1100 AND 1010 equals 1000.
What does left shift by 2 do to 12?
It gives 48, since 1100 shifted two places is 110000.
Which operation keeps bits set in exactly one operand?
XOR.
Questions
What are bitwise operators?
Operations that act on individual binary digits of integers.
What is AND used for?
Masking out bits by combining with zeros.
What does XOR do?
It sets a bit when exactly one input bit is set.
How does left shift relate to multiplication?
Shifting left by n multiplies by two to the power n.
Why 32 bit unsigned?
It matches common language behaviour for these operators.
Can I use negative numbers?
Not on this page. Operands must be nonnegative.
Sources
- University of Alaska Fairbanks, Bits and Bitwise Operators
- Carnegie Mellon University, 15-750 Compression lecture notes