XOR & Bitwise Calculator

Run any bitwise operation on two integers and see the result in decimal, binary and hex, with the operands lined up bit by bit.

Result
A
B
Result

What each operation does

OperationRule, bit by bit
XOR ^1 when the two bits differ, 0 when they match
AND &1 only when both bits are 1
OR |1 when at least one bit is 1
NOT ~Flips every bit; on signed integers ~x equals −x−1
Left shift <<Moves bits left, filling with zeros; each place doubles the value
Right shift >>Moves bits right, keeping the sign bit; each place halves, rounding down

Why XOR is the interesting one

XOR is its own inverse: (a ^ b) ^ b = a. Applying the same key twice returns the original, which is the basis of the simplest stream ciphers, of swapping two variables without a temporary, and of parity and checksum schemes. It is also the only one of the three binary operations that loses no information — given the result and either operand you can always recover the other, which is impossible for AND and OR.

Worked example

60 XOR 13

  1. 60 = 0011 1100
  2. 13 = 0000 1101
  3. Compare each column: 1 where the bits differ
  4.     0011 0001
  5. = 49 (0x31)

Check the reversibility: 49 XOR 13 = 60, back where we started.

Frequently asked questions

What does XOR mean?

Exclusive OR. Comparing two numbers bit by bit, each output bit is 1 when the two input bits differ and 0 when they are the same.

What is 60 XOR 13?

49. In binary, 60 is 00111100 and 13 is 00001101; the bits differ in four columns, giving 00110001, which is 49 in decimal and 0x31 in hex.

Why is XOR used in encryption?

Because it is its own inverse. Applying the same key twice with XOR returns the original data, so encryption and decryption are the same operation, and no information is lost in either direction.

What is the difference between XOR and OR?

OR gives 1 when at least one bit is 1, including when both are. XOR gives 1 only when exactly one bit is 1, so it returns 0 when both bits are 1.

What does the NOT operator return for a positive number?

On signed integers, NOT x equals minus x minus one. So NOT 5 is minus 6, because flipping every bit in two's complement representation produces that result.

Related calculators

Boolean FunctionSMD Resistor CodeHCF & LCM