# Properly simulating a NAND gate? (I'm building a computer in my computer)

I am about to embark on a project, enspired by Nand2Tetris (http://www.nand2tetris.org/), to fully simulate a computer, building the entire thing up from NAND gates.

I want to simulate everything from scratch, starting with a primitive implementation of a NAND gate that simulates how a NAND gate would work on the physical level, and then connect them together to build a computer.

The thing is, I don't understand enough about how a NAND gate would work on the physical level in order to write this.

To be clear, this is certainly not what I am looking for:

def nand(a, b)
return !(a && b)
end


I'd like to implement the NAND gate as a class, so it functions more like an actual object. I'd like it to have pins, and I'd like to be able to connect the pins together and apply voltage, etc.

Can someone show me how you might implement a proper simulation of a physical NAND gate, one that could be linked together to ultimately build a computer?

-

## migrated from stackoverflow.comJan 14 '13 at 18:00

This question came from our site for professional and enthusiast programmers.

While I think what you're doing is great, I think this question is a bit too broad for Stack Overflow. How low-level are you talking about here? At the level of individual transistors? Individual atoms? – templatetypedef Jan 11 '13 at 5:44
Great question. I think transistors would be a good starting point. Atoms, lets save that for a later project :) – MikeC8 Jan 11 '13 at 7:30
If your project is to "build the whole thing up from NAND gates," like you say in your first paragraph, then you shouldn't worry about how NAND gates are physically realized. If you do that, you're building the whole thing up from transistors, not from gates. – The Photon Jan 15 '13 at 3:01