Skip to content
Tactiverge

Digital logic

XOR gate

Also called: exclusive or · XOR · A ⊕ B · parity · difference detector

Definition

An XOR gate outputs 1 when its inputs are different and 0 when they are the same.

Picture it

XOR is a 'difference detector'. It is the sum bit of a binary adder, it computes parity for simple error checks, and XORing with 1 toggles a bit. A two-way staircase light switch is XOR logic.

The maths

Y = A ⊕ B = A·B̄ + Ā·B
A B | Y: 00|0 01|1 10|1 11|0
SI units used in this entry
QuantityUnitSymbol
ratiodimensionless1

Worked example

What is 0b1100 XOR 0b1010, and what is the even-parity bit for the data 1011 0010?

  1. Bits differ in positions 2 and 1 → 0110 = 6
  2. Data has four 1s; XOR of all bits = 0
  3. Even parity bit = 0 (total number of 1s stays even)

Answer0110 (decimal 6); parity bit 0.

✓ The 2 numbers in this answer are recomputed from scratch by an automated test.

logic tester

Logic gate tester

Y = 1

Y = A ⊕ B

Truth table for XOR; the current row is marked.
ABY
000
011
101 ◀ now
110
XOR with A = 1, B = 0 gives Y = 1.

Ideal gates: no propagation delay. 1 = true = high, 0 = false = low.

Common misconceptions

  • Misconception: XOR is not the same as OR; 1 XOR 1 is 0.
  • Misconception: A single parity bit catches one flipped bit but misses two.