

Ask HN: Logic Gates (Be Gentle: I'm New to This) - shawndumas

I was trying to fill in some gaps and was looking at logic gates and the article said that all of them can be made from NAND. I loaded up my JS REPL and this is my first pass:<p><pre><code>  var lgs = {
        nand: function (a, b) {
                return !(a &#38;&#38; b);
        },
        not:  function (a)    {
                return lgs.nand(a, a);
        },
        and:  function (a, b) {
                return lgs.not(lgs.nand(a, b));
        },
        or:   function (a, b) {
                return lgs.nand(lgs.nand(a, a), lgs.nand(b, b));
        },
        nor:  function (a, b) {
                return lgs.not(lgs.or(a, b));
        },
        xor:  function (a, b) {
                return lgs.and(lgs.nand(a, b), lgs.or(a, b));
        },
        xnor: function (a, b) {
                return lgs.not(lgs.xor(a, b));
        }
    };
</code></pre>
Questions:
.<p>1.) can 'or' and 'xor' be simpler?
.<p>2.) why is it called 'xor'?
.<p>3.) are there any in browser simulators?
.<p>4.) where should I go from here?
======
shaunxcode
Get a copy of "The Elements of Computing Systems"

[http://www.amazon.com/Elements-Computing-Systems-Building-
Pr...](http://www.amazon.com/Elements-Computing-Systems-Building-
Principles/dp/0262640686/ref=sr_1_1?ie=UTF8&s=books&qid=1284740379&sr=8-1)

[http://books.google.com/books?id=THie6tt-2z8C&dq=the+ele...](http://books.google.com/books?id=THie6tt-2z8C&dq=the+elements+of+computing+systems&printsec=frontcover&source=bn&hl=en&ei=YZWTTPaqDZC6sQOPhPTACg&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCwQ6AEwAw)

which will seriously take you from logic gate/chip design all the way to
scripting languages and an implementation of tetris on a java-esque
language/vm. Totally awesome!

You can download the simulation software which is used in the book here if you
want to play w/ logic gates/HDL etc. more <http://www1.idc.ac.il/tecs/>

~~~
shawndumas
found a nice online one[1]

[1]: <http://news.ycombinator.com/item?id=1702112>

------
FreeFull
xor stands for exclusive or. Basically it means that if 1 and 1 are passed to
it, it will return 0, while or would return 1.

------
darkxanthos
your nand function is a nand or'd with a nor... Why did you do it this way?

~~~
shawndumas
doh! (thanks)

