Lesson 4 of 15

XOR & XNOR Gates

XOR and XNOR Gates

XOR (Exclusive OR) outputs 1 when inputs are different:

ABXORXNOR
0001
0110
1010
1101

XNOR is the complement of XOR — it outputs 1 when inputs are equal.

XOR is fundamental in digital arithmetic:

  • Half adder: sum bit = A XOR B
  • Parity checker: XOR of all bits tells you if count of 1s is odd
  • Comparator: A XNOR B tells you if two bits are equal

In JavaScript, XOR is the ^ operator:

1 ^ 0  // 1
1 ^ 1  // 0

Your Task

Implement xor(a, b) and xnor(a, b), then print all four combinations for each.

JavaScript loading...
Loading...
Click "Run" to execute your code.