XOR as a One-Bit Inequality Test

An exclusive-or gate outputs one when exactly one input is one. With two single bits, this is the condition that they differ.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Read the mixed and tied rows
  2. Build a word-level check
  3. Read XOR as a different-input result
  4. Distinguish parity from detecting any difference

Read the mixed and tied rows

Inputs 0 and 1 yield one. Inputs 1 and 1 yield zero. Applying the same gate independently across two words produces a bitwise XOR indicating each changed position.

Build a word-level check

If several positions feed XOR outputs, OR-ing those outputs yields one when any position disagrees. This is a circuit example of a Boolean reduction using existential logic.[1]

Read XOR as a different-input result

Two status bits agree on zero-zero and one-one, so XOR is low in both cases. It goes high when one bit is low and the other high. For a word, bitwise XOR marks every differing position. See bitwise toggling.

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
Word example: 1010 XOR 1100 = 0110

Distinguish parity from detecting any difference

XOR of many bits reports an odd number of ones. If a comparison word contains two differences, reducing all its bits with XOR yields zero even though the words differ. Detect any difference by comparing the entire difference word with zero.

References

  1. Noam Nisan and Shimon Schocken, From Nand to Tetris: Course Projects ↩