Gate Simulator

XOR Gate Simulator

Interactive XOR gate simulator with truth table, boolean expression, and real circuit examples. Learn how exclusive OR works in binary addition and error detection.

Overview

The XOR (Exclusive OR) gate outputs HIGH only when its inputs are different from each other. When both inputs are the same — both 0 or both 1 — the output is LOW. This "exclusive" behaviour distinguishes XOR from the ordinary OR gate, which outputs 1 when both inputs are 1. XOR is the "either, but not both" gate.

The boolean expression for XOR is Y = A ⊕ B, where the ⊕ symbol denotes exclusive OR. This can also be written in standard boolean form as Y = A'B + AB' — the output is 1 when A is 0 and B is 1, or when A is 1 and B is 0. XOR is critically important in digital arithmetic because it computes the sum bit of two binary digits without carrying.

XOR gates appear in adders, parity generators, error detection/correction circuits, hash functions, and cryptographic operations. The 74HC86 is a classic quad 2-input XOR gate IC. XOR is also the basis of many secret-sharing and one-time-pad encryption schemes because XORing a message with a random key produces perfectly random ciphertext.

Truth Table

Y = A ⊕ B (equivalently: Y = A'B + AB')
ABOutput (Y)
000
011
101
110

How It Works

A 2-input XOR gate requires more transistors than AND or OR gates — typically 8 transistors in CMOS. It is constructed from a combination of NAND and inverter stages, or from a transmission gate topology.

The key insight is that XOR can be decomposed: Y = A ⊕ B = A'B + AB'. This means: use two AND gates (one with A inverted, one with B inverted), and then OR the results. This 4-gate implementation (two ANDs + two NOTs + one OR) is common in educational contexts, though real ICs use optimised transistor-level designs.

XOR has the remarkable property of self-inverse: A ⊕ B ⊕ B = A. XORing any value with itself gives 0; XORing with 0 preserves the value; XORing with 1 inverts the value. This makes XOR perfect for parity and cryptographic operations.

Real-World Applications

Binary Addition (Half Adder)

The sum output of a half adder is computed using XOR: Sum = A ⊕ B. A full adder extends this with carry-in.

Parity Generators and Checkers

XORing all bits of a word generates a parity bit. Re-XORing at the receiver detects single-bit errors.

Error Detection and Correction

CRC (Cyclic Redundancy Check) and Hamming codes rely on XOR operations to detect and correct transmission errors.

Cryptography and Encryption

One-time pad encryption XORs plaintext with a key. XOR ciphers are reversible: the same operation decrypts the message.

Bit Toggling in Programming

In software, XOR with a bitmask toggles specific bits without affecting others — used in toggle switches and bitfield manipulation.

Try It in the Interactive Simulator

Build XOR Gate circuits in real time — drag gates, connect wires, toggle inputs, and see outputs update instantly.

Frequently Asked Questions

  • What is the difference between XOR and OR?

    OR outputs 1 when any input is 1, including when both inputs are 1. XOR outputs 1 only when inputs are different — when both are 1, XOR outputs 0.

  • What is the boolean expression for XOR?

    Y = A ⊕ B, which expands to Y = A'B + AB'. The output is 1 when exactly one input is 1.

  • Why is XOR used in binary adders?

    The sum of two single bits (without carry) is exactly the XOR: 0+0=0, 0+1=1, 1+0=1, 1+1=0 (sum bit only, carry is separate). XOR computes the least significant bit of addition.

  • What is the IC number for XOR gate?

    The 74HC86 is a quad 2-input XOR gate in CMOS. The 74LS86 is its TTL equivalent.

  • What is the relationship between XOR and XNOR?

    XNOR is the complement of XOR. XNOR outputs 1 when inputs are the same; XOR outputs 1 when inputs are different. Y_XNOR = (A ⊕ B)'.