Adders and flip-flops
Adders and flip-flops
- Logic gates can do real work: adders do binary arithmetic, flip-flops remember a bit.
- These are the building blocks of the ALU and of memory.
- (Recall the gate symbols from the logic-gates lesson.)
The half adder
- A half adder adds two single bits, giving a sum $S$ and a carry $C$:
| A | B | S | C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
- So $S = A \text{ XOR } B$ and $C = A \text{ AND } B$. It ignores any carry-in — hence "half".
In a half adder, the sum output S is produced by which gate?
$S = A \text{ XOR } B$ (1 when the inputs differ); the carry is $A \text{ AND } B$.
In a half adder, the carry output C is produced by which gate?
$C = A \text{ AND } B$ — a carry occurs only when both inputs are 1.
The full adder
- A full adder adds three bits ($A$, $B$, and a carry-in), giving a sum and a carry-out.
- $S = A \text{ XOR } B \text{ XOR } C_{\text{in}}$. It can be built from two half adders plus an OR gate.
- Chaining full adders (each carry-out feeding the next carry-in) makes a multi-bit ripple-carry adder.
How does a full adder differ from a half adder?
A full adder adds A, B and a carry-in (so adders can be chained) — built from two half adders plus an OR gate.
Flip-flops
- A flip-flop is bistable (two stable states) — it remembers one bit. It's the basic element of registers and SRAM.
- An SR flip-flop (set/reset):
S=1,R=0sets Q to 1;S=0,R=1resets it;S=0,R=0holds;S=1,R=1is invalid. - A JK flip-flop uses the invalid
1,1input as a toggle (the output flips) — ideal for counters. It is usually clocked so flip-flops stay synchronised.
A flip-flop is used to:
A flip-flop has two stable states and holds one bit — the building block of registers and SRAM.
The JK flip-flop improves on the SR flip-flop by making the previously invalid 1,1 input:
JK turns the forbidden SR input into a useful toggle, which is ideal for building counters.
You've got it
- half adder: $S = A \text{ XOR } B$, $C = A \text{ AND } B$ (no carry-in)
- full adder: adds 3 bits (incl. carry-in) = two half adders + an OR; chain them for a ripple-carry adder
- a flip-flop is bistable and stores one bit (registers, SRAM)
- SR (set/reset, 1/1 invalid); JK uses 1/1 as a toggle — good for counters