Give a gate a rule
AND outputs 1 only when both inputs are 1. Inclusive OR outputs 1 when either or both inputs are 1. XOR outputs 1 when exactly one input is 1. Flip the inputs and compare every row of the truth table.
Flip real input bits on a little calculator. Build a result from simple rules, and follow a carry as it crosses four columns.
Enable JavaScript to change the conditions and run the interactive experiment.
Binary uses place values 1, 2, 4, 8 and so on. In one column, 1+1 leaves a sum bit of 0 and carries a 1 to the next column. That is why one plus one is written 10 in binary.
What is 15 + 15 + carry-in 1 in five-bit binary?
15+15+1=31. In binary, 16+8+4+2+1=11111. The fifth bit matters.
AND outputs 1 only when both inputs are 1. Inclusive OR outputs 1 when either or both inputs are 1. XOR outputs 1 when exactly one input is 1. Flip the inputs and compare every row of the truth table.
A half-adder uses XOR for its sum and AND for its carry. A full-adder also accepts a carry from the previous column. A full-adder does not need to remember earlier calculations; it depends on its current inputs.
The carry leaving the 1s column enters the 2s column, then the 4s and 8s columns. A fifth bit preserves the final carry. This is a ripple-carry adder: a different kind of ripple from the traffic lesson, with a precisely defined dependency chain.
For inputs A, B and Cᵢₙ: S=A XOR B XOR Cᵢₙ. Cₒᵤₜ=(A AND B) OR (Cᵢₙ AND (A XOR B)). Every one of the eight input combinations is defined.
Two unsigned four-bit numbers and one carry-in can sum to 31. That needs five bits: 11111. Silently discarding the fifth bit would wrap the result modulo 16. This lesson keeps it.
A logic 1 is not universally 1 volt. Real devices specify valid voltage ranges, loading and delays. The highlights here show evaluation order, not electrons, wire speed or measured nanoseconds.
Write 0 on one side and 1 on the other. Try all four input pairs for a half-adder. Use separate cards for sum and carry.
Try three input cards. Count how many ones there are: an odd count makes sum 1; two or more makes carry 1.
Set up four place-value columns and add 7+1. Pass each carry into the next column, retaining a fifth result bit.
Can simple rules add a number without a calculator?
Paper actions reproduce Boolean rules, not electronic timing. Use folded paper instead of scissors if needed.
Original course-author gate contracts and truth-table testing.
Nand2Tetris · Boolean logicOriginal arithmetic component specifications.
Nand2Tetris · Boolean arithmeticThe SN74HC86 implements four two-input XOR functions. No electrical timing values are imported into the model.
Texas Instruments · XOR datasheetIndependent subject review is pending.
Read the sources and model assumptions