{"id":172,"date":"2009-01-30T00:00:36","date_gmt":"2009-01-30T07:00:36","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=639"},"modified":"2009-01-30T00:00:36","modified_gmt":"2009-01-30T07:00:36","slug":"canonical-representation-of-xor","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=172","title":{"rendered":"Canonical Representation of XOR"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ xor\r\ntrace(0 ^ 0);\r\ntrace(0 ^ 1);\r\ntrace(1 ^ 0);\r\ntrace(1 ^ 1);\r\n\r\ntrace(&quot;canonical representation of xor&quot;);\r\ntrace(xor(0, 0));\r\ntrace(xor(0, 1));\r\ntrace(xor(1, 0));\r\ntrace(xor(1, 1));\r\n\r\nfunction xor(a:int, b:int):int{\r\n\t\/\/1-a   is the same as   int(!a)\r\n\treturn 1-a &amp; b | a &amp; 1-b;\r\n}\r\n\r\n\/*\r\noutputs:\r\n0\r\n1\r\n1\r\n0\r\ncanonical representation of xor\r\n0\r\n1\r\n1\r\n0\r\n*\/\r\n<\/pre>\n<p>I learned about this from reading <a href=\"http:\/\/www1.idc.ac.il\/tecs\/\">The Elements of Computing Systems: Building a Modern Computer from First Principles By Noam Nisan and Shimon Schocken<\/a><\/p>\n<p>Check out chapter 1 from the above link for an easy to understand description of the canonical representation of a boolean function.<\/p>\n<p><i>Just a side note&#8230; this happens to be the 100th post on actionsnippet.com<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ xor trace(0 ^ 0); trace(0 ^ 1); trace(1 ^ 0); trace(1 ^ 1); trace(&quot;canonical representation of xor&quot;); trace(xor(0, 0)); trace(xor(0, 1)); trace(xor(1, 0)); trace(xor(1, 1)); function xor(a:int, b:int):int{ \/\/1-a is the same as int(!a) return 1-a &amp; b | a &amp; 1-b; } \/* outputs: 0 1 1 0 canonical representation of xor 0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,36],"tags":[3,4],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-one-liners","category-operators","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}