XOR from only OR and AND

John Zane picture John Zane · Jan 17, 2011 · Viewed 27.5k times · Source

How do you do the XOR bitwise operation if you only have available the AND and the OR operations?

Answer

Lou Franco picture Lou Franco · Jan 17, 2011

Truth table for AND

  A  B  AND
  T  T  T
  T  F  F
  F  T  F
  F  F  F
  

Truth table for OR

  A  B  OR
  T  T  T
  T  F  T
  F  T  T
  F  F  F
  

Truth table for XOR

  A  B  XOR
  T  T  F
  T  F  T
  F  T  T
  F  F  F
  

So, XOR is just like OR, except it's false if A and B are true.

So, (A OR B) AND (NOT (A AND B)), which is (A OR B) AND (A NAND B)

  A  B  OR  AND NAND [(A OR B) AND (A NAND B)]
  T  T  T    T    F        F
  T  F  T    F    T        T
  F  T  T    F    T        T
  F  F  F    F    T        F
  

Not sure if it can be done without NOT or NAND