Loading slide

The Logic

  1. 01The Logic
  2. 02The connection
  3. 03Try it yourself
  4. 04What did you notice?
  5. 05Both must agree
  6. 06Either will do
  7. 07Here's an analogy to hammer home the point
  8. 08The inverter
  9. 09Gates talk to each other
  10. 10Three gates, one circuit
  11. 11Three rules
  12. 12Building logic
  13. 13A simple comparison
  14. 14Turn the rule into gates
  15. 15Flip before you compare
  16. 16Small rules stack up
  17. 17Take a breath
  18. 18What is 1+1?
  19. 19Addition, from scratch
  20. 20Two gates, that's it
  21. 21Memory
  22. 22Reinforce your understanding
  23. 23Question: AND gate
  24. 24Question: NOT gate
  25. 25Question: Binary addition
  26. 26Quiz: answer
  27. 27One switch
  28. 28Want to go deeper?
19 / 27
BackNext

Addition, from scratch

So we need to produce two answers: the carry and the sum. Let's find a gate for each.

The carry first. It should be 1 only when both inputs are 1 (that's the 1+1 case). We have already met a gate that does exactly that: AND.

Now the sum. Look at when it should be 1: for 0+1 and 1+0, but not for 1+1. It's almost OR, except OR also fires on 1+1, and we don't want that.

So we use one new gate, XOR. It means "one or the other, but not both." 0 and 1 gives 1. 1 and 1 gives 0. That is the sum column, exactly.

Wire AND and XOR to the same two inputs, and you have a circuit that adds two bits.

Two gates. That's addition, built from nothing but logic.

Citations(2)↓
  1. 1. nand2tetris.org
  2. 2. charlespetzold.com
Citations(2)↓
  1. 1. nand2tetris.org
  2. 2. charlespetzold.com