Development & CodeLive🔒 Private

Logic XOR XNOR Simulator

Simulate XOR and XNOR logic gate combinations. Free online logic gate tool. No signup, 100% private, browser-based.

Logic XOR XNOR Simulator

XOR

1

XNOR

0

How it works

XOR (exclusive OR) outputs HIGH when inputs differ: out = A ⊕ B. XNOR (exclusive NOR) outputs HIGH when inputs are equal: out = !(A ⊕ B). XOR is used extensively in digital arithmetic, error detection, and cryptography.

**XOR applications** Binary addition: the sum bit in a half adder = A XOR B; carry = A AND B. Full adders chain these together. Error detection: parity bits — XOR all data bits; the result is the parity bit appended to the data. Even parity: XOR should be 0. XOR in CRC (cyclic redundancy check) for error detection in communications. Cryptography: XOR with a key stream produces symmetric encryption (one-time pad is XOR-based).

**XOR as a controlled inverter** XOR(A, 1) = !A (when B=1, XOR inverts A). XOR(A, 0) = A (when B=0, XOR passes A unchanged). This makes XOR useful as a programmable inverter — the second input is a control signal. Used in bit manipulation, flip operations, and cipher implementations.

**XNOR for equality comparison** XNOR(A, B) = 1 when A = B. For multi-bit equality comparison: XOR corresponding bits pairwise; NOR all results. If result is HIGH, all bits match. This is how digital comparator circuits work. Used in pattern matching, address decoding, and synchronization detection.

**XOR swap trick** XOR allows value swapping without a temporary variable: A = A XOR B; B = A XOR B; A = A XOR B. This works because XOR is its own inverse. Primarily of academic interest — compilers generate better code using a temp variable, and the XOR swap fails when A and B point to the same memory location.

Frequently Asked Questions

How is XOR used in CRC error detection?
CRC (Cyclic Redundancy Check) treats a data stream as a polynomial and divides it by a generator polynomial using XOR arithmetic (polynomial division with XOR instead of subtraction). The remainder is the CRC checksum appended to the data. At the receiver, the same division is performed — if the remainder is zero, no errors occurred. XOR's properties make this mathematically elegant: division is reversible, XOR is its own inverse, and error patterns are detectable with high probability. CRC-32 detects all single and double-bit errors, all odd-number-of-bit errors, and all burst errors shorter than 32 bits.
Why is XOR used in RAID storage redundancy?
RAID-5 stores a parity block: XOR of all data blocks on remaining drives. To recover a failed drive, XOR all surviving drive blocks — the result is the lost data (because A XOR B XOR (A XOR B) = 0, so A = B XOR C when C = A XOR B). XOR is perfect for this: it's its own inverse, operates bit-by-bit without carry, and the recovery is fast and lossless. RAID-6 uses two parity schemes (one XOR, one Reed-Solomon polynomial), allowing any two drives to fail simultaneously and still recover all data.
How does XOR enable simple encryption?
XOR cipher: plaintext XOR key = ciphertext; ciphertext XOR key = plaintext (because XOR is its own inverse). A one-time pad (OTP) uses a truly random key as long as the message — provably unbreakable. Stream ciphers (AES-CTR, ChaCha20) generate a pseudorandom keystream that is XORed with plaintext. XOR's property: if the key is uniformly random and never reused, every ciphertext bit has equal probability of being 0 or 1 regardless of the plaintext — perfect secrecy. Weakness: reusing the same XOR key for two messages allows recovery: C1 XOR C2 = P1 XOR P2 (key cancels), exposing plaintext patterns.
What is an XNOR comparator and how is it used in digital circuits?
XNOR(A,B) = 1 when A = B. A 4-bit equality comparator: XNOR each pair of bits, then AND all four XNOR outputs — output is 1 only when all four bit-pairs match. This pattern scales to any bit width. Uses: address decoding (detect when an address bus matches a specific value), instruction decoding (match specific opcodes), data comparison (equality testing in processors), and error checking (compare received data with expected). For inequality (A > B or A < B), magnitude comparators use a more complex logic network beyond simple XNOR.