What is XOR (Exclusive-OR (Logical Operation))

XOR: Exclusive OR (Logical Operation)

XOR (Exclusive OR) is a logical operation that outputs true (1) when an odd number of inputs are true, and false (0) otherwise. It's denoted by the symbol ⊕.

Truth Table

Input AInput BOutput (A XOR B)
000
011
101
110

Export to Sheets

Properties of XOR

  • Commutative: A ⊕ B = B ⊕ A
  • Associative: (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)
  • Identity element: A ⊕ 0 = A
  • Inverse element: A ⊕ A = 0
  • Linearity: A ⊕ (B ⊕ C) = (A ⊕ B) ⊕ C = A ⊕ B ⊕ C

XOR Gate

An XOR gate is a digital logic gate that performs the XOR operation. It has two inputs and one output.

Opens in a new windowanalog.comXOR gate

Applications of XOR

  • Error Detection: XOR is used in parity checking to detect single-bit errors in data transmission.
  • Cryptography: XOR is used in various cryptographic algorithms, such as encryption and decryption.
  • Hamming Code: XOR is used in Hamming codes for error correction.
  • Checksum Calculation: XOR is used in checksum algorithms to verify data integrity.
  • Arithmetic Operations: XOR is used in binary addition without carry.
  • Pseudo-Random Number Generation: XOR can be used in linear feedback shift registers (LFSRs) for generating pseudorandom sequences.

Example: Parity Checking

Let's consider a simple example of parity checking using XOR. Suppose we have a data block: 10110. To calculate the parity bit, we perform XOR on all bits:

1 XOR 0 XOR 1 XOR 1 XOR 0 = 1

The parity bit is 1. If a single bit error occurs during transmission, the calculated parity bit at the receiver will not match the transmitted parity bit, indicating an error.

Conclusion

XOR is a fundamental logical operation with wide-ranging applications in computer science, digital electronics, and cryptography. Its ability to detect differences and its properties make it a valuable tool in various algorithms and systems.