menuGamaTrain
search

chevron_left XOR: TRUE if exactly one input is TRUE (exclusive OR) chevron_right

XOR: TRUE if exactly one input is TRUE (exclusive OR)
Anna Kowalski
share
visibility6
calendar_month2026-02-19

XOR: The “Exactly One” Logic Gate

Exclusive OR — a digital logic fundamental that lights up only when inputs differ.
Summary: The XOR (exclusive OR) operation outputs TRUE only when the number of true inputs is exactly one. Unlike the standard OR, which is true if at least one input is true, XOR demands exclusivity. This article explores the truth table, the Boolean expression $A \oplus B = A\overline{B} + \overline{A}B$, practical applications like parity checking and controlled inverters, and common questions from beginners. We also cover how XOR behaves with more than two inputs and why it is the basis for binary addition without carry.

1. What Does “Exactly One” Mean? The XOR Truth Table

Imagine you have two light switches and a special bulb that lights up only when exactly one switch is ON. That is XOR in a nutshell. In Boolean logic, inputs and outputs can only be TRUE (1) or FALSE (0). For two inputs A and B, the XOR output $A \oplus B$ follows a simple rule: it is 1 if A and B are different, and 0 if they are the same. The table below shows all four possibilities.

Input AInput BXOR Output (A ⊕ B)
000 (same inputs → false)
011 (different inputs → true)
101 (different inputs → true)
110 (same inputs → false)

Notice how XOR behaves like “not equal”. In fact, for two bits, $A \oplus B$ is exactly the same as $A \neq B$. This is why XOR is often called a difference detector.

2. The Boolean Algebra Behind XOR

Mathematically, XOR can be built from the basic AND, OR, and NOT operations. The standard formula is:

XOR formula: $A \oplus B = (A \cdot \overline{B}) + (\overline{A} \cdot B)$

Here the overbar means NOT, the dot $\cdot$ means AND, and the $+$ means OR. The expression says: “A is true and B is false, OR A is false and B is true.” Exactly the condition for exclusive OR. You can also think of XOR as a parity function: it returns 1 if an odd number of inputs are 1. For two inputs, “odd” means exactly one.

3. Extending XOR: Three or More Inputs

What happens when you have three inputs A, B, and C? XOR remains associative, so $A \oplus B \oplus C$ means you apply XOR to the first two, then XOR that result with the third. The rule becomes: output is TRUE if the number of true inputs is odd. For three inputs, that means true when exactly one input is true OR when all three are true (since three is odd). Let’s see it in action.

ABCA ⊕ B ⊕ C
0000
0011
0101
0110
1001
1010
1100
1111

4. Where XOR is Used: Parity and Controlled Inversion

XOR is a workhorse in computer engineering. One classic use is parity generation for error detection. When sending data, an extra bit (the parity bit) is added to make the total number of 1s either even (even parity) or odd (odd parity). XOR computes this efficiently. For even parity, the parity bit is simply the XOR of all the data bits.

Example – Even parity for 4 bits: $P = D_1 \oplus D_2 \oplus D_3 \oplus D_4$
If the data bits are 1,0,1,1 (three 1s), then $P = 1 \oplus 0 \oplus 1 \oplus 1 = 1$ (odd). To make the total even, we actually want the opposite: for even parity we need the XOR of all five bits (including P) to be 0. That’s why parity is often implemented with XOR trees.

Another vital use is a controlled inverter. If you take an input A and XOR it with a control C, then:

  • If $C=0$, output = $A \oplus 0 = A$ (no change).
  • If $C=1$, output = $A \oplus 1 = \overline{A}$ (flipped).

This property is used in cryptography (stream ciphers) and in arithmetic circuits. In fact, a half adder—the simplest circuit for adding two bits—uses XOR for the sum bit: $Sum = A \oplus B$ and AND for the carry.

5. Important Questions About XOR

Q: Is XOR the same as “not equal”?
A: For two Boolean inputs, yes. The truth table for $A \neq B$ is identical to $A \oplus B$. However, for more than two inputs, “not equal” is not a standard operation, while XOR is well-defined as odd parity.
Q: How do I build an XOR gate using AND, OR, and NOT?
A: Use the formula $A \oplus B = (A \cdot \overline{B}) + (\overline{A} \cdot B)$. You need two AND gates, two NOT gates, and one OR gate. Alternatively, you can use NAND gates only.
Q: What is the output of $X \oplus X$?
A: Zero. Since both inputs are the same (both 0 or both 1), the XOR rule says output is 0. This property makes XOR useful for clearing registers: $X \oplus X = 0$.
Conclusion: XOR is a fundamental logic operation with a simple yet powerful definition: true only when an odd number of inputs are true. From detecting differences in bits to building adders and checking data integrity, XOR appears everywhere in digital systems. Understanding it is a stepping stone to mastering binary arithmetic, cryptography, and error detection. Remember, for two inputs it is the “difference” function, and for multiple inputs it is the “odd parity” function.

Footnote

[1] XOR: Exclusive OR. A logical operation that outputs true only when the inputs are different (for two inputs) or when an odd number of inputs are true (for any number).
[2] Boolean algebra: A branch of algebra dealing with true/false values and logical operations (AND, OR, NOT).
[3] Parity: A technique that counts the number of 1-bits in a binary sequence. Even parity means the total number of 1s is even; odd parity means it is odd.
[4] Half adder: A digital circuit that adds two bits, producing a sum (XOR) and a carry (AND).

Did you like this article?

home
grid_view
add
explore
account_circle