Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Logic Gates (Be Gentle: I'm New to This)
3 points by shawndumas on Sept 17, 2010 | hide | past | favorite | 5 comments
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:

  var lgs = {
        nand: function (a, b) {
                return !(a && 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));
        }
    };
Questions: .

1.) can 'or' and 'xor' be simpler? .

2.) why is it called 'xor'? .

3.) are there any in browser simulators? .

4.) where should I go from here?



Get a copy of "The Elements of Computing Systems"

http://www.amazon.com/Elements-Computing-Systems-Building-Pr...

http://books.google.com/books?id=THie6tt-2z8C&dq=the+ele...

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/


found a nice online one[1]

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


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.


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


doh! (thanks)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: