The SR Latch remembers one bit, but its outputs follow the inputs for as long as S or R is held. Real computers need a bit that changes only at a chosen instant, so that many bits can be updated together. That instant is the edge of a clock pulse. In this lesson you will meet the two clocked flip-flops named in the CAPE syllabus, the D (Data) flip-flop and the JK flip-flop, see how a row of them makes a register, and build a 2-bit ripple counter that counts 00, 01, 10, 11, 00 on every falling clock edge.
What you will learn
- The difference between a latch (level-sensitive) and a flip-flop (edge-triggered).
- How a D flip-flop copies D to Q on a clock edge and holds it otherwise.
- The four JK actions: hold, reset, set and toggle, and how J = K = 1 makes a toggle (T) flip-flop.
- How n flip-flops with a shared clock make an n-bit register.
- How two toggle flip-flops, with Q0 clocking the second one, make a 2-bit ripple counter that counts on the negative edge.
- How to model a register and a ripple counter in C.
Part 1: From a latch to a clocked flip-flop
A latch is level-sensitive: while the inputs are active, the output can change at any moment. That is awkward when you want a whole word of bits to update together. A flip-flop is edge-triggered: it looks at its inputs only at the moment the clock changes, and holds its value the rest of the time.
- A rising (positive) edge is the change from 0 to 1.
- A falling (negative) edge is the change from 1 to 0.
A flip-flop can be built to use either edge. The widgets in this lesson all use the falling (negative) edge, because that is how the ripple counter in Part 5 is wired. In a question, read the triangle on the clock input: a small bubble (inverting circle) on the clock means negative-edge triggered; no bubble means positive-edge triggered.
Part 2: The D (Data) flip-flop
The D flip-flop has one data input D and a clock. On the triggering edge it copies D into Q, and Q′ becomes the opposite. Between edges it holds, whatever D does. In symbols, the next state is simply Q+ = D. That single rule is why the D flip-flop is the usual building block of registers: there is no forbidden input, and you just present the bit you want to store and tick the clock.
| D at the falling edge | Q becomes | Name |
| 0 | 0 | Store a 0 (reset) |
| 1 | 1 | Store a 1 (set) |
Try it 1D flip-flop (falling edge)
Set D, then tap CLK to raise and lower the clock. Q takes the value of D only when CLK falls from 1 to 0.
Part 3: The JK flip-flop
The JK flip-flop has two inputs, J and K, plus a clock. It is the most general of the simple flip-flops: with the right combination of J and K it can hold, reset, set or toggle. The four actions (applied on the triggering edge) are:
| J | K | Action on the falling edge | Next Q |
| 0 | 0 | Hold (no change) | Q |
| 0 | 1 | Reset | 0 |
| 1 | 0 | Set | 1 |
| 1 | 1 | Toggle (flip Q) | NOT Q |
Compare this with the SR latch: J is like S and K is like R, but J = K = 1 is no longer forbidden — it is the most useful case. A JK flip-flop with J and K both tied to 1 (or a single T input held at 1) is called a T (toggle) flip-flop. It flips on every triggering edge, and that is exactly what a binary counter needs.
Try it 2JK flip-flop (falling edge)
Choose J and K, then raise and lower CLK. The action is carried out only on the falling edge.
Part 4: Registers
A register is a group of flip-flops that share the same clock, one flip-flop per bit. An 8-bit register is eight D flip-flops side by side: when the clock edge arrives, each flip-flop stores its own D input, so the whole word is loaded at once. The CPU registers you will meet in The Processor: CPU Components and the Fetch-Decode-Execute Cycle (the program counter, the accumulator, the instruction register and so on) are built this way. Because they sit inside the processor they are the fastest storage a computer has; see Memory Types and Features.
If the D input of each flip-flop is taken from the Q of its neighbour, the same register becomes a shift register: on each clock edge every bit moves one place to the left or right. Shift registers are used in serial communication and in some arithmetic circuits. For CAPE, the important picture is: flip-flops plus a common clock = a register; n flip-flops store n bits.
Part 5: A 2-bit ripple counter
A counter is a register wired so that its bit pattern steps through a fixed sequence, usually the binary numbers. The simplest is the ripple (asynchronous) counter. For two bits:
- Both flip-flops are toggles: J and K are tied to 1, so each one flips when it sees a falling edge on its own clock.
- The external clock goes only to FF0, the least significant bit (Q0).
- Q0 is wired to the clock input of FF1, the most significant bit (Q1).
Follow one cycle, starting at Q1 Q0 = 00, and remember that a flip-flop only changes when its clock falls:
| Falling edge of CLK | Q0 (FF0) | Does Q0 fall? | Q1 (FF1) | Count |
| 1st | 0 → 1 | No (it rose) | 0 (holds) | 01 = 1 |
| 2nd | 1 → 0 | Yes | 0 → 1 | 10 = 2 |
| 3rd | 0 → 1 | No | 1 (holds) | 11 = 3 |
| 4th | 1 → 0 | Yes | 1 → 0 | 00 = 0 |
It is called a ripple counter because a change has to work its way, or ripple, along the chain: FF1 cannot toggle until Q0 has already fallen. In real hardware that ripple takes a little time, so a 16-bit ripple counter is slower than a synchronous counter, in which every flip-flop shares the same clock and the toggling is decided by combinational logic. For two bits the delay is tiny, and CAPE mainly asks you to trace the falling-edge behaviour above. (An older animation of the same idea is The Ripple Counter Explained (Animation).)
Try it 32-bit ripple counter (negative edge)
Both flip-flops are JK toggles (J = K = 1). The clock goes to FF0; Q0 is the clock for FF1. Tap the clock to raise and lower it, or tap Pulse once for a full high-then-low tick. Outputs change only on the falling edge, which is highlighted, and a timing diagram builds as you go.
Count
Clock low (hold)
Timing diagram. Yellow columns mark a falling edge of CLK, where the count changes.
Part 6: Flip-flops, registers and counters in C
C does not have a flip-flop type, but the rules are ordinary assignment. The program below is the 2-bit ripple counter from Part 5. A loop flips a clk variable eight times (four complete pulses). The outputs change only in the branch that sees a falling edge, and Q1 flips only when Q0 was 1 (so Q0 is about to fall).
#include <stdio.h>
/* A 2-bit ripple counter.
q0 toggles on every falling clock.
q1 toggles only when q0 falls. */
int main(void)
{
int clk = 0, prev;
int q0 = 0, q1 = 0;
int step;
printf("step clk Q1 Q0 count\n");
printf(" 0 0 %d %d %d\n",
q1, q0, q1 * 2 + q0);
for (step = 1; step <= 8; step++) {
prev = clk;
clk = 1 - clk; /* tick */
if (prev == 1 && clk == 0) {
int old0 = q0;
q0 = 1 - q0; /* FF0 */
if (old0 == 1)
q1 = 1 - q1; /* FF1 */
}
printf("%4d %d %d %d",
step, clk, q1, q0);
printf(" %d\n", q1 * 2 + q0);
}
return 0;
}
Output:
step clk Q1 Q0 count 0 0 0 0 0 1 1 0 0 0 2 0 0 1 1 3 1 0 1 1 4 0 1 0 2 5 1 1 0 2 6 0 1 1 3 7 1 1 1 3 8 0 0 0 0
Read the table: on the odd steps the clock has just risen and the count is unchanged; on the even steps the clock has fallen and the count has moved on, 0, 1, 2, 3, then back to 0. That is the timing diagram in Try it 3, written as text.
A register is even simpler: an array of bits (see Arrays in C). This program “loads” three numbers into a 4-bit register by storing each bit, rightmost first. Between loads the bits just sit there, which is what a register does between clock edges.
#include <stdio.h>
/* A 4-bit register: an array of bits.
Load stores a number. A later clock
does not change it until we load
again. */
int main(void)
{
int q[4] = {0, 0, 0, 0};
int values[3] = {5, 13, 0};
int v, i, b, n;
for (n = 0; n < 3; n++) {
v = values[n];
/* bit 0 is on the right */
for (i = 0; i < 4; i++) {
q[i] = v % 2;
v = v / 2;
}
printf("loaded %d: ", values[n]);
for (b = 3; b >= 0; b--)
printf("%d", q[b]);
printf("\n");
}
return 0;
}
Output:
loaded 5: 0101 loaded 13: 1101 loaded 0: 0000
Try this: extend counter.c to three bits, with q2 toggling when q1 falls. It should count from 0 to 7 and wrap. How many falling clock edges does one full cycle need?
Try it 4Flip-flop and counter drill
Choose a type of question. For JK answers you can type 00, 01, 10 or 11, or the word hold, reset, set or toggle when you are asked for the action.
Summary
| Idea | Key points |
| Latch vs flip-flop | A latch follows its inputs while they are held (level-sensitive). A flip-flop updates only on a clock edge and holds otherwise. |
| D flip-flop | Q+ = D on the triggering edge. The usual cell for a register. |
| JK flip-flop | 00 hold, 01 reset, 10 set, 11 toggle. J = K = 1 is a T flip-flop. |
| Register | n flip-flops with a common clock store an n-bit word. A shift register moves bits along on each edge. |
| Ripple counter | Toggle flip-flops in a chain; each Q clocks the next. A 2-bit counter cycles 00, 01, 10, 11. The count changes on the negative edge of CLK. |
| Synchronous counter | Every flip-flop shares the same clock, so there is no ripple delay. Know that it exists; CAPE tracing questions usually use the ripple picture. |
Practice questions
1. A falling-edge D flip-flop has Q = 1 and D = 0. The clock goes 0 → 1 → 0. What is Q after the rising edge, and after the falling edge?
Show answer
After the rising edge Q is still 1 (hold). After the falling edge Q becomes 0, a copy of D.
2. A JK flip-flop has J = 1, K = 0 and Q = 0. What is Q after one falling edge? What if J and K are both 1 instead?
Show answer
J = 1, K = 0 is set, so Q becomes 1. If J = K = 1 it toggles, so Q becomes 1 as well in this case (because it started at 0).
3. Why is J = K = 1 allowed in a JK flip-flop when S = R = 1 is forbidden in an SR latch?
Show answer
The JK flip-flop is edge-triggered and the 11 input is defined as toggle, a useful action. The SR latch is level-sensitive, and S = R = 1 forces Q and Q′ both to the same value, which is inconsistent.
4. How many flip-flops does a 16-bit register need? What about a counter that must count from 0 to 15?
Show answer
16 flip-flops for the register (one per bit). A 0-to-15 counter also needs 4 flip-flops, because 24 = 16 patterns.
5. A 2-bit ripple counter holds 10 (decimal 2). After one falling clock edge, what are Q1 and Q0? Explain which flip-flops toggled.
Show answer
Q0 toggles 0 → 1, which is a rising edge for FF1, so Q1 holds at 1. The new count is 11 (decimal 3).
6. Why is a long ripple counter slower than a synchronous counter with the same number of bits?
Show answer
In a ripple counter each flip-flop is clocked by the previous Q, so a change must propagate down the chain. In a synchronous counter every flip-flop is clocked at the same instant.
7. A 4-bit register holds 0110. All four D inputs are set to 1, but the clock does not tick. What does the register hold? What does it hold after one triggering edge?
Show answer
It still holds 0110, because a register only loads on a clock edge. After the edge it holds 1111.
Homework
- Draw a D flip-flop and a JK flip-flop. For each one write the rule for Q+ and, on the JK, the four-row action table from memory. Check yourself against Parts 2 and 3.
- Starting at 00, copy the timing diagram in Try it 3 onto paper for eight clock edges (four pulses). Label every falling edge and the decimal count. Then use Auto-clock to check.
- On paper, add a third toggle flip-flop FF2 whose clock is Q1. Complete the 3-bit count from 000 to 111. Then extend
counter.cand confirm. - Read The SR Latch again, then explain in four sentences how a clocked JK flip-flop is related to the SR latch and why the extra clock is worth having.
Exam tips
Specimen Unit 1 Paper 01 (2021), Item 11. A multiple-choice item about statements on flip-flops, including that a register is made of flip-flops and that a flip-flop is a two-state device. Know those two facts, and be ready to reject a statement that treats a flip-flop as a fault rather than as a memory element.
2013 Unit 1 Paper 02, Question 1. An early part asks for characteristic features of flip-flops. Answer in terms of two stable states, a clock (edge-triggered update) and the use of flip-flops to build registers and counters. See the worked solution 2013 U1 Q1.
2009 Unit 1 Paper 02, Question 1 and later papers sometimes combine gates, flip-flops and a counter or a multiplexer in one long question. Being able to trace a 2-bit ripple count, as in Try it 3, is the skill those parts use. See 2009 U1 Q1 and 2024 U1 Q2.
General advice: always say which edge you are using; trace a counter one flip-flop at a time from the clock towards the high bits; and when a question asks how many flip-flops you need, use one per bit (or 2n states for an n-bit counter). More worked answers are on the CS Solutions page.
Previous: The SR Latch (lesson 11). Next: Multiplexers, Encoders and Decoders. See also: Logic Gates and Truth Tables and The Ripple Counter Explained (Animation).
Syllabus link: CAPE Computer Science (CXC A19/U2/21), Unit 1, Module 1: Computer Architecture. Specific Objective 2: describe the basic building blocks of a computer (flip-flops: Data, JK and SR; registers; counters). Specific Objective 3: interpret the interaction among the basic building blocks (data flip-flops, registers).
Video search terms
Search YouTube for: "D flip-flop explained", "JK flip-flop truth table", "2-bit ripple counter falling edge", "register from D flip-flops".
Try it 5Quick quiz
Tap an answer. All eight questions are self-checks on this lesson.
Updates
2026/11/23
- Removed the Print this lesson button.
- Fixed a typo in the opening paragraph.
- Published.
© 2026 Vedesh Kungebeharry. All rights reserved.