Skip to content
BetterDL

XOR gate

Also called: exclusive OR, exclusive-OR gate, EOR gate, EXOR gate, XOR logic gate

A logic gate whose output is 1 when its two inputs are different and 0 when they match. Written A ⊕ B, it equals A'B + AB'.

An XOR gate (exclusive OR) outputs 1 when its inputs are different: one is 1 and the other is 0. When both are 0 or both are 1, it outputs 0. It is written , shown as A ⊕ B, and typed with ^.

Compare it with OR. The two agree in rows 00, 01 and 10. They differ only in row 11, where OR gives 1 and XOR gives 0. "Exclusive" means one or the other, but not both.

Using only AND, OR and NOT, XOR is : one term picks out row 01, the other row 10.

Why XOR shows up everywhere:

  • Adding bits. The sum bit of 1-bit addition is XOR (0, 1, 1, 0), so XOR sits at the heart of every half adder and full adder.
  • Controlled inversion. = A and = , so one input can decide whether the other is flipped. See xor identities.
  • Parity. A multi-input XOR outputs 1 when an odd number of inputs are 1, which is how parity bits are made.
  • Comparing. XOR is 1 exactly where two bits disagree.

The symbol is the OR shape with an extra curved line behind the inputs.

ABY

Worked examples

Example

Deriving XOR's expression from its table

XOR is 1 in rows 01 and 10 only. Write it with AND, OR and NOT.

0000
0111
1011
1100
  1. 1.

    Row 01 needs A = 0 and B = 1: the term .

  2. 2.

    Row 10 needs A = 1 and B = 0: the term .

  3. 3.

    The output is 1 when either term is 1, so OR them: .

  4. 4.

    Check row 11: = 0 and = 0, so the output is 0, as XOR requires.

Example

A 4-input XOR

Find for A = 0, B = 1, C = 1, D = 1.

  1. 1.

    Count the 1s: B, C and D, so three.

  2. 2.

    Three is odd, so the output is 1.

  3. 3.

    Chaining agrees: 0 ⊕ 1 = 1, then 1 ⊕ 1 = 0, then 0 ⊕ 1 = 1.

Common mistakes

  • Giving 1 for row 11. That's OR. XOR is 0 when both inputs are 1.

  • Thinking a 3-input XOR is 1 only when exactly one input is 1. It is 1 for any odd count, so 111 gives 1 too.

  • Mixing XOR with AND and OR without brackets. Write rather than relying on a precedence rule your reader may not share.

Practice XOR gate

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

XOR gate is taught in Logic Gates.