What you can do here
- AND, OR and XOR of two integers
- NAND, NOR and XNOR (the inverted forms)
- NOT (one's complement) of A or B
- Left shift, right shift and unsigned right shift
- Mix input bases:
255,0xFFand0b11111111are the same number
Click an operation (or a table row) to highlight it and see its bits lined up. The choice is kept in the address, for example /bitwise-calculator?op=xor, so you can share a calculation.
How the calculator works
Both inputs are converted to 32-bit signed integers, exactly as JavaScript, Java, C# and C do for int, and the language's bitwise operators are applied. The decimal column is the signed result; the hexadecimal and binary columns show the unsigned 32-bit pattern (via >>> 0), so a signed result of -6 is printed as 0xFFFFFFFA.
What each operation does
| Operation | Operator | Meaning |
|---|---|---|
| AND | a & b | 1 only where both bits are 1. Used to test or mask bits. |
| OR | a | b | 1 where either bit is 1. Used to combine flags. |
| XOR | a ^ b | 1 where the bits differ. Used to toggle bits and spot changes. |
| NAND | ~(a & b) | The inverse of AND: 0 only where both bits are 1. |
| NOR | ~(a | b) | The inverse of OR: 1 only where both bits are 0. |
| XNOR | ~(a ^ b) | The inverse of XOR: 1 where the bits are equal. |
| NOT | ~a | Flips every bit; for signed integers ~a = -a - 1. |
| Left shift | a << b | Moves bits left by b, multiplying by 2b and dropping bits past bit 31. |
| Right shift | a >> b | Moves bits right, copying the sign bit: a floor divide by 2b. |
| Unsigned right shift | a >>> b | Moves bits right, filling with zeros; negative numbers become large positives. |
Truth table
| 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 |
Worked example
A = 12 (1100), B = 10 (1010):
AND : 8 (1000)
OR : 14 (1110)
XOR : 6 (0110)
NAND : -9 (0xFFFFFFF7)
NOR : -15 (0xFFFFFFF1)
XNOR : -7 (0xFFFFFFF9)
12 << 10 = 12288
12 >> 10 = 0 (every bit shifted past the end)
When you would use it
Checking whether a permission or feature-flag bit is set (flags & MASK), combining options into one integer (|), toggling a bit (^), clearing a bit (& ~bit), reading packed protocol or hardware register fields with shifts and masks, or checking logic-gate homework.
Common questions
Why does a large shift amount seem to wrap around?
JavaScript, Java and C# use only the low 5 bits of the shift count for 32-bit shifts, so x << 33 behaves like x << 1. Keep the shift between 0 and 31.
Why do NAND, NOR, XNOR and NOT give negative numbers?
They flip the high bits too. In a 32-bit signed integer the top bit is the sign, so ~12 is -13. The hex and binary columns show the same result as an unsigned pattern, such as 0xFFFFFFF3.
Can I enter hex or binary?
Yes. Prefix hex with 0x (0xFF) and binary with 0b (0b1010); plain numbers are decimal. Underscores and spaces inside a number are ignored.
Can it handle numbers above 32 bits?
No. Inputs are coerced to 32-bit integers, so use whole numbers from -2147483648 to 4294967295 (values above 2147483647 wrap to negative, just as they do in code).
Is my input uploaded?
No. Everything is computed in the page with native operators; nothing is sent anywhere.