Actionscript:

// xor

trace(0 ^ 0);

trace(0 ^ 1);

trace(1 ^ 0);

trace(1 ^ 1);


trace("canonical representation of xor");

trace(xor(0, 0));

trace(xor(0, 1));

trace(xor(1, 0));

trace(xor(1, 1));


function xor(a:int, b:int):int{

//1a is the same as int(!a)

return 1a & b  a & 1b;

}


/*

outputs:

0

1

1

0

canonical representation of xor

0

1

1

0

*/
I learned about this from reading The Elements of Computing Systems: Building a Modern Computer from First Principles By Noam Nisan and Shimon Schocken
Check out chapter 1 from the above link for an easy to understand description of the canonical representation of a boolean function.
Just a side note... this happens to be the 100th post on actionsnippet.com
2 Comments
“Just a side note… this happens to be the 100th post on actionsnippet.com”  Congratulations! I really enjoy feeding from all your snippets.
Thanks Ted… glad you enjoy it