Bitwise Calculator
Enter two numbers and a shift amount — every bitwise result updates live in all five bases.
Bitwise Operations
How to calculate bitwise AND, OR and XOR
- Pick a base. Type numbers in binary, quinary, octal, decimal or hexadecimal.
- Enter two numbers. The results update live as you type.
- Read the results. AND, OR, XOR, NOT, NAND, NOR, XNOR and both shifts appear below, each in all five bases.
- Change the shift amount. Edit n to see A << n and A >> n update live.
One-bit rules
Every bitwise operation compares one bit at a time. These are the rules for a single pair of bits:
| A | B | AND | OR | XOR | NAND | NOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
NOT works on a single number: NOT 0 = 1 and NOT 1 = 0.
Worked example: A = 12, B = 10
In binary, 12 is 1100 and 10 is 1010. Apply the one-bit rules column by column:
| Operation | Binary result | Decimal |
|---|---|---|
| AND | 1000 | 8 |
| OR | 1110 | 14 |
| XOR | 0110 | 6 |
| NOT A | — | −13 |
| NAND | — | −9 |
| NOR | — | −15 |
| XNOR | — | −7 |
| A << 2 | 110000 | 48 |
| A >> 2 | 11 | 3 |
NOT, NAND, NOR and XNOR flip every bit with no fixed width, so their results are negative: ~A = −A − 1. For example, ~12 = −13 and ~(12 AND 10) = ~8 = −9.
Frequently asked questions
What is a bitwise operation?
A bitwise operation works on the individual bits of a number instead of the number as a whole. AND, OR, XOR, NAND, NOR and XNOR compare two numbers bit by bit; NOT flips every bit of one number; shifts move all bits left or right. Type two numbers above and every result updates live.
What is 12 AND 10?
12 AND 10 = 8. In binary, 12 is 1100 and 10 is 1010. Compare each column: 1 AND 1 = 1, 1 AND 0 = 0, 0 AND 1 = 0, 0 AND 0 = 0, giving 1000, which is 8 in decimal.
How does bitwise NOT work?
NOT flips every bit: each 1 becomes 0 and each 0 becomes 1. Because the flip applies to every bit with no fixed width, ~5 = −6, ~12 = −13, and in general ~A = −A − 1. That is why the NOT result above is negative even when A is positive.
What is the difference between AND, OR and XOR?
AND gives 1 only when both bits are 1. OR gives 1 when at least one bit is 1. XOR gives 1 when the bits differ — one 1 and one 0. NAND is AND followed by NOT, NOR is OR followed by NOT, and XNOR is XOR followed by NOT, so XNOR gives 1 when the bits are equal.
How do left shift and right shift work?
Left shift (A << n) moves every bit n places left and fills the right with 0s — the same as multiplying by 2^n. Right shift (A >> n) moves every bit n places right and drops the bits that fall off — the same as dividing by 2^n and rounding down. Example: 12 << 2 = 48, and 12 >> 2 = 3.
How do I do bitwise operations in Python?
Python has operators for all of them: & for AND, | for OR, ^ for XOR, ~ for NOT, << for left shift and >> for right shift. Example: 12 & 10 gives 8, 12 | 10 gives 14, 12 ^ 10 gives 6, ~12 gives −13, 12 << 2 gives 48 and 12 >> 2 gives 3.