Wednesday, May 8, 2013

Xor Gate


Truth Table
a b | f(a,b)
------------
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 0

Boolean Expression
(!x*y)+(x*!y)

----------------------------------------

CHIP Xor
{
    IN a, b;
    OUT out;

    PARTS:
    Not(in=a, out=aNot);
    Not(in=b, out=bNot);
    And(a=aNot, b=b, out=out1);
    And(a=a, b=bNot, out=out2);
    Or(a=out1, b=out2, out=out);
}

----------------------------------------

Another that might seem hard at first but adding a few gates together does the trick.  Seeing as you want to know when its one or the other and not both the first and gate returns a 1 only if y is 1 and x is not, and the second does the the opposite returns a 1 if x is 1 and y is not.  Then its just a matter of outputing a 1 if either AND gate returned a 1.

No comments:

Post a Comment