Browse lessons

XOR and XNOR gates

Compare two inputs and detect whether their values match.

For two inputs, XOR detects different values and XNOR detects matching values. These operations are useful in comparisons and binary addition.

XOR gate

XOR outputs 1 when exactly one of its two inputs is 1.

Turn on one switch, then the other. Notice that the output returns to 0 when both inputs are on.

Click an input to change its value.Out: 0
ABOutput
000
011
101
110

XNOR gate

XNOR outputs 1 when both inputs have the same value. Its output is the inverse of XOR.

The editor includes an XNOR component. This example builds the same function from XOR followed by NOT.

Click an input to change its value.XNOR: 1
ABOutput
001
010
100
111

Use XOR in addition

XOR calculates the sum bit when adding two one-bit inputs. An AND gate calculates the carry bit.

See Build a half adder for the combined circuit.