AlgoViz

Bitwise XOR

easy 14 min

XOR compares two numbers bit by bit and outputs 1 wherever they differ.

Where it shows up

The same pattern appears across everyday software.

  • RAID 5 storage arrays

    Each stripe stores a parity block equal to the XOR of its data blocks. When one drive dies, XORing the surviving blocks with the parity rebuilds the lost data exactly.

  • Error detection and ECC memory

    Parity bits are the XOR of a group of data bits. Network protocols, storage and ECC RAM use XOR-based codes to detect, and with Hamming codes correct, flipped bits.

  • Stream ciphers and the one-time pad

    Ciphertext is message XOR keystream, and the receiver XORs with the same keystream to decrypt. With a truly random key used once, the output reveals nothing; AES-CTR and ChaCha20 work this way.

  • XOR drawing in graphics

    Early GUIs drew cursors and rubber-band selection boxes by XORing pixels. Drawing the same shape a second time erased it and restored the background without storing it.

  • Hash functions and game engines

    FNV hashing XORs each input byte into the state before multiplying. Chess engines use Zobrist hashing: a position's key is the XOR of random numbers per piece and square, so a move updates it with two XORs.