XOR

Inputs

PinTypeDescription
AbitFirst input signal
BbitSecond input signal

Outputs

PinTypeDescription
Qbit1 if A≠B

How It Works

XOR is the everyday "or... or, but not both". A classic example: stairway light switches at both ends — flip either one, and the light toggles. The gate answers a short question: "are the inputs different?".

The key property: the output is 1 when the inputs differ and 0 when they match. Two useful tricks follow. XOR(A,1) flips a bit — a controlled inverter. And XOR(A,A) is always 0, which is why processors clear registers this way. A bigger example: XOR of two identical bytes gives 00000000 — this is how data is compared for equality.

A nuance: XOR is not a basic gate; in the game you assemble it at Level 5 from simpler parts using the formula AND(OR(A,B), NAND(A,B)). Mathematicians call it addition modulo 2: in binary, 1+1=10, but XOR keeps only the low bit — the carry vanishes. That is exactly why XOR is the heart of every adder.

Truth Table and Examples

ABQ
000
011
101
110

Parity check example: run a byte through a chain of XORs (7 gates for 8 bits) — the output is 1 if the byte contains an odd number of ones. This is how parity bits are formed, catching a single flipped bit during data transmission.

Usage

XOR is unlocked at Level 5 and immediately becomes the workhorse of arithmetic: the sum bit in the half adder (Level 6) is a pure XOR, and the full adder and ALU use several in a row. The bus version BusXOR applies the operation to a whole byte.

Concrete applications: a difference detector (compare two bits or two bytes — a zero result means "equal"), controlled inversion (XOR with a one or a mask flips selected bits), parity bits and simple checksums. Even encryption uses XOR: apply the key to the data twice and you get the original data back.

Interactive Demo

Click inputs to toggle value (0 / 1)

Build it yourself →

Related components

Related articles

Frequently Asked Questions

What is XOR used for?

Detecting differing values, checksums and controlled inversion: XOR with 1 flips a bit.

How is XOR related to adders?

XOR computes the sum bit of two numbers, AND computes the carry bit. Together they form a half adder.

How do I build XOR from basic gates?

Using AND(OR(A,B), NAND(A,B)): four gates. The logic: "at least one one" AND "not both at once".

Why is XOR called addition modulo 2?

Because it adds bits and discards the carry: 1+1=10 in binary, but XOR outputs only the low bit — 0. It is addition "without remainder".