Bitwise AND OR XOR Calculator

Enter two non-negative whole numbers to compute AND, OR and XOR.

How it is calculated

Both fields take whole numbers from 0 up to 9,223,372,036,854,775,807 (263 − 1), typed in ordinary decimal. The tool compares the two numbers bit by bit: A & B keeps a 1 only where both numbers have a 1, A | B keeps a 1 where at least one has it, and A ^ B keeps a 1 where exactly one has it. Digit strings are read as exact integers, so large values keep every digit. The three results are printed in decimal with digit grouping, and the XOR is also printed as a binary string with no leading zeros (an XOR of 0 shows as 0). Negative numbers, decimals, binary or hex text and values above the limit give no result, so two's complement is not modelled.

Worked example

Take A = 202 and B = 153. In binary 202 is 11001010 and 153 is 10011001. AND keeps the positions that are 1 in both, giving 10001000, which is 136. OR keeps positions that are 1 in either, giving 11011011, which is 219. XOR keeps positions where they differ, giving 01010011, which is 83, shown as 1010011. Check: AND + XOR = 136 + 83 = 219, the OR value.

Try this example →

Common mistakes

  • Typing the numbers in binary or hexadecimal. The fields take decimal only, so enter 202, not 11001010 or CA; text like 0xCA returns no result.
  • Expecting a negative number to work through two's complement. Negative inputs are rejected, so convert them to their unsigned form yourself first.
  • Confusing bitwise AND with the logical AND used on true and false. This works on every bit of the number, so 12 and 10 gives 8, not true.
  • Reading the XOR binary string as a fixed width. It has no leading zeros, so 83 appears as 1010011 and not as an 8-bit value.
  • Entering a number above 9,223,372,036,854,775,807. That is the signed 64-bit maximum, and anything larger shows no result.

About this calculator

Bitwise AND, OR and XOR compare two numbers one binary digit at a time. AND returns 1 only where both numbers have a 1 in that position, OR returns 1 where either number has a 1, and XOR (exclusive or) returns 1 only where exactly one of the two numbers has a 1 — meaning matching bits cancel out to 0. Applying an operation to every bit position at once is what makes these ‘bitwise’ rather than the plain logical AND/OR used on whole true/false values.

Programmers use bitwise AND to mask off specific bits — such as checking a subnet mask against an IP address, or testing whether a particular flag is set in a bitfield — bitwise OR to combine flags together, and XOR for tasks like toggling bits, swapping two values without a temporary variable, simple stream ciphers, and detecting differences between two binary values, since XOR-ing something with itself always produces zero.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators