Skip to main content
Data / Number / Computer Science Tools

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.

Bitwise 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

  1. Enter two non-negative integers.
  2. Choose AND, OR, XOR, or NOT (which only needs one operand).
  3. 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):

OperationBinaryResultRule
AND100081 only where both bits are 1
OR1110141 where either bit is 1
XOR011061 where the bits differ

Practical Uses

  • Check a flag: permissions & WRITE is 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 & 1 is 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

They compare two numbers bit by bit. AND gives 1 only if both bits are 1, OR if either is 1, and XOR if exactly one is 1.

& works on each bit of two numbers. && works on whole true/false values and is used in conditions.

Flags and permission masks, checking whether a number is even (n & 1), network subnet masks, and low-level data processing.
Share this tool: