Bitwise AND/OR/XOR Calculator
Calculate bitwise AND, OR, XOR, and NOT on two numbers - shows binary and decimal results, clearly distinct from logical operators.
Enter two numbers and choose a bitwise operation - this tool shows both operands' binary representation and the resulting binary/decimal value.
These are true bitwise operators (act on individual bits), not logical operators (&&, ||) which act on whole true/false values. JavaScript performs bitwise operations on 32-bit signed integers, so results are limited to that range.
More Data / Number / Computer Science Tools
View all 19Bitwise operators work on individual bits, unlike logical operators (&&, ||) which work on whole true/false values - this tool performs true bitwise operations, not logical ones.
Bitwise vs. Logical Operators
Bitwise AND/OR/XOR compare each corresponding bit position of two numbers independently - this is different from logical AND/OR, which treat each entire operand as a single true/false value. Mixing these up is a common source of bugs in real code.
How to Use It
- Enter two non-negative integers.
- Choose AND, OR, XOR, or NOT (which only needs one operand).
- View both operands in binary alongside the result, plus the decimal value.
Limitations
Calculations use JavaScript's native 32-bit bitwise operators, matching how bitwise operations behave in most programming languages for standard integer sizes - values requiring more than 32 bits aren't supported here, since bitwise semantics for arbitrary-precision integers vary by language/context.
Example
With 12 (1100) and 10 (1010):
| Operation | Binary | Result | Rule |
|---|---|---|---|
| AND | 1000 | 8 | 1 only where both bits are 1 |
| OR | 1110 | 14 | 1 where either bit is 1 |
| XOR | 0110 | 6 | 1 where the bits differ |
Practical Uses
- Check a flag:
permissions & WRITEis non-zero if the write bit is set. - Set a flag:
permissions | WRITE. - Clear a flag:
permissions & ~WRITE. - Toggle a flag:
permissions ^ WRITE. - Subnetting: an IP address AND its subnet mask gives the network address.
- Odd or even:
n & 1is 1 for odd numbers.
A Common Bug
In most languages, & and | are bitwise while && and || are logical. 2 & 1 is 0 (no shared bits), but 2 && 1 is true. Writing one when you mean the other compiles fine and fails silently.
Move bits around with the Bit Shift Calculator, and check values with Decimal to Binary.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.