Core Lesson Content
Crossing the Digital Bridge
Lesson 4 ended with a comparator slamming between two rails β an analog circuit producing only two answers. This lesson makes those two answers a complete language. Half the lesson is how digital systems count (number systems and binary arithmetic); the other half is how they decide (gates and Boolean algebra). Both halves rest on the same premise:
The transistor connection matters: a MOSFET (Lesson 3) driven fully on or fully off is a logic level. Wire a few of them together and you get the gates in this lesson; wire a few billion and you get a processor.
Try It Live
Decimal and Binary: One Idea, Two Bases
You already know the only concept required: place value. In decimal, 347 means 3Γ100 + 4Γ10 + 7Γ1 β each column weighs ten times its neighbor. Binary works identically with columns weighing two times their neighbor:
Binary β Decimal: Add the Weights
Write the weights over the bits and sum wherever a 1 appears. That's the entire method β and exactly what the Digital Lab's Binary Explorer animates as you click bits.
Decimal β Binary: Two Methods
- Repeated division by 2: divide, keep the remainder, repeat; read remainders bottom-up. 25 β 12 r1 β 6 r0 β 3 r0 β 1 r1 β 0 r1 gives 11001β.
- Greatest-weight subtraction: subtract the largest power of 2 that fits, mark that bit 1, repeat. 25 β 16 = 9, β 8 = 1, β 1 = 0 β 11001β. Faster mentally once the weights are memorized.
Octal and Hexadecimal: Binary Shorthand
Nobody enjoys reading 1010111101101001. Octal and hex exist to compress binary for humans, and both work by the same beautiful accident of powers: 8 = 2Β³ and 16 = 2β΄, so one octal digit is exactly 3 bits and one hex digit is exactly 4 bits (a nibble).
The Grouping Shortcut (no arithmetic required)
1 010 111 101 101 001β β group by 3 β 1 2 7 5 5 1 β 127551β
Grouping starts from the right (LSB). Convert hexβbinary by expanding each digit back to its 4 bits. Between octal and hex? Go through binary β it's the common language.
| Dec | Bin | Oct | Hex | Dec | Bin | Oct | Hex |
|---|---|---|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 8 | 1000 | 10 | 8 |
| 1 | 0001 | 1 | 1 | 9 | 1001 | 11 | 9 |
| 2 | 0010 | 2 | 2 | 10 | 1010 | 12 | A |
| 3 | 0011 | 3 | 3 | 11 | 1011 | 13 | B |
| 4 | 0100 | 4 | 4 | 12 | 1100 | 14 | C |
| 5 | 0101 | 5 | 5 | 13 | 1101 | 15 | D |
| 6 | 0110 | 6 | 6 | 14 | 1110 | 16 | E |
| 7 | 0111 | 7 | 7 | 15 | 1111 | 17 | F |
Arithmetic in Base-N
Binary Addition: Four Facts Total
Worked example:
1011 (11)
+ 0111 (7)
ββββββ
1 0010 (18) β
The rhythm is identical to decimal addition β you just carry at 2 instead of at 10. The same is true in any base: hex carries at 16 (9 + 8 = 11ββ, i.e., "one-one": 1 carry, 1 down).
Binary Subtraction
Borrowing works (0 β 1 borrows a 2 from the next column), but real hardware doesn't bother: it adds the 2's complement instead β one adder circuit, both operations. That trick is the whole next tab.
Hex Arithmetic
+ 2Cββ (44)
βββββ
66ββ (102) β (A+C = 10+12 = 22 = 16+6 β write 6, carry 1)
Signed Binary: 2's Complement
Bits have no minus sign, so we spend one bit to encode it. The naive approach (sign-magnitude) creates two zeros and breaks the adder. The universal solution is 2's complement, where the MSB carries negative weight:
Negating a Number: Invert and Add One
Check: β128+64+32+4+2+1 = β25 β
Why Hardware Loves It
- Subtraction = addition: A β B is computed as A + (βB). One adder does everything; the carry out of the top bit is simply discarded.
- One zero, instant sign test: MSB = 1 means negative, full stop.
- Overflow is detectable: add two positives and get a negative (0111 1111 + 1 = 1000 0000, i.e., 127+1 = β128) β the classic wraparound. Watch it live in the Lab with the SIGNED toggle on.
The Five Fundamental Gates
A logic gate is a transistor circuit that computes one Boolean operation. Its complete personality fits in a truth table β list every input combination (2βΏ rows) and the output for each. Master these five tables and you can read any digital schematic:
| Gate | Expression | Output is 1 when⦠| Memory Hook |
|---|---|---|---|
| AND | X = AΒ·B | ALL inputs are 1 | Series switches β both must close |
| OR | X = A+B | ANY input is 1 | Parallel switches β either path works |
| NOT | X = A̅ | Input is 0 | The flip β one in, opposite out |
| NAND | X = (AΒ·B)̅ | NOT all inputs are 1 | AND flipped β 0 only at 1,1 |
| NOR | X = (A+B)̅ | ALL inputs are 0 | OR flipped β 1 only at 0,0 |
Reading the Symbols
- Shape carries meaning: flat-backed D = AND family; curved shield = OR family; triangle = buffer/inverter.
- The bubble is a NOT: NAND is literally the AND symbol wearing a bubble. No bubble, no inversion.
- The dot and plus are operators, not arithmetic: AΒ·B reads "A AND B"; A+B reads "A OR B". In Boolean land 1+1 = 1.
NAND and NOR: The Universal Gates
Here is one of digital design's most elegant facts: you don't need five gate types. NAND alone can build everything β and so can NOR. A gate with this property is called universal.
Building the Basics from NAND
- NOT: tie both NAND inputs together. (AΒ·A)̅ = A̅ β the idempotent law in action.
- AND: NAND followed by that NAND-inverter. Two gates.
- OR: invert each input, then NAND them: A̅ NAND B̅ = (A̅Β·B̅)̅ = A + B β which is DeMorgan's theorem doing the heavy lifting. Three gates.
The NOR story is the perfect mirror (swap the roles of AND and OR throughout β Boolean algebra's duality principle).
Why This Matters Beyond Elegance
- Silicon economics: in CMOS, NAND is the cheapest, fastest gate to fabricate β so real chips are seas of NAND with everything else synthesized from it. ("NAND flash" memory earned its name honestly.)
- Inventory reality: a technician with a tube of 7400 quad-NAND ICs can prototype any logic function on the bench.
- Historical proof: the Apollo Guidance Computer was built entirely from one gate type β 3-input NOR β about 5,600 of them, navigating to the Moon.
The Laws of Boolean Algebra
Boolean algebra lets you simplify a circuit on paper before spending gates on it. Fewer gates means lower cost, less power, and fewer failure points. The laws come in memorable pairs β every AND rule has an OR twin (duality):
| Law | AND form | OR form | Plain English |
|---|---|---|---|
| Identity | A Β· 1 = A | A + 0 = A | Neutral elements change nothing |
| Null | A Β· 0 = 0 | A + 1 = 1 | Dominating elements decide everything |
| Idempotent | A Β· A = A | A + A = A | Repetition is redundant |
| Complement | A Β· A̅ = 0 | A + A̅ = 1 | A thing and its opposite |
| Commutative | AΒ·B = BΒ·A | A+B = B+A | Order doesn't matter |
| Associative | AΒ·(BΒ·C) = (AΒ·B)Β·C | A+(B+C) = (A+B)+C | Grouping doesn't matter |
| Distributive | AΒ·(B+C) = AΒ·B + AΒ·C | A+(BΒ·C) = (A+B)Β·(A+C) | The second form has no decimal twin! |
| Involution | A̅̅ = A | Double negation cancels | |
Worked Simplification
= AΒ·(B + B̅) β distributive (factor A)
= AΒ·(1) β complement law
= A β identity law
Three gates collapsed to a piece of wire β and the truth tables of the original and simplified expressions are identical, which is the only test that matters.
DeMorgan's Theorems and Truth Table Analysis
Augustus DeMorgan's two theorems are the master keys of gate-level reasoning β they convert freely between the AND world and the OR world:
(A + B)̅ = A̅ Β· B̅ NOR = AND of inverted inputs
The verbal rule: break the bar, change the operator (Β· β +), and complement each term. The schematic rule: a bubble on a gate's output can be "pushed" to its inputs if you also swap the gate's shape β invaluable when a schematic is drawn in mixed logic.
Proof by Truth Table
| A | B | AΒ·B | (AΒ·B)̅ | A̅ | B̅ | A̅+B̅ |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
Columns four and seven match on every row β the theorem is proven, no algebra required. This column-by-column construction is the general method for analyzing any combinational circuit: work from the inputs through each intermediate signal to the output, one column per node.
Analysis Procedure for Any Gate Network
- Label every internal node on the schematic.
- Build a truth table with a column for each node, filling left to right.
- The final column is the circuit's function β compare it against the five standard tables (or a required spec).
- Optionally, write the Boolean expression by composing gate expressions from output back to inputs, then simplify with Tab 8's laws and re-verify by table.