3 ms·
Ask HN: Logic Gates (Be Gentle: I'm New to This)
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?
- FreeFull 16y agoxor 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.
- shaunxcode 16y agoGet a copy of "The Elements of Computing Systems" 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://www.amazon.com/Elements-Computing-Systems-Building-Pr... 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 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/ http://www1.idc.ac.il/tecs/
- shawndumas 16y agofound a nice online one[1] [1]: http://news.ycombinator.com/item?id=1702112 http://news.ycombinator.com/item?id=1702112
- darkxanthos 16y agoyour nand function is a nand or'd with a nor... Why did you do it this way?
- shawndumas 16y agodoh! (thanks)