How to build a 2-bit multiplier from logic gates
A 2-bit binary multiplier multiplies A1 A0 by B1 B0 to give a 4-bit product P3 P2 P1 P0, using four AND gates for the partial products and two half adders to add them: P0 = A0 B0, P1 = A1 B0 XOR A0 B1, and the carries form P2 and P3.
It is long multiplication in binary. Each bit of B times A is just an AND, because the only digits are 0 and 1, so the partial products are A0B0, A1B0, A0B1 and A1B1. Shift them into columns and add: column 0 has one term, column 1 has two (a half adder), and column 2 has A1B1 plus the carry from column 1 (a second half adder), whose carry is P3. The live circuit starts at 0 x 0; try 11 x 11 for 3 x 3 = 9.
Open this circuit in the lab →
What you need
- 4× AND: the partial products A0B0, A1B0, A0B1, A1B1
- 2× XOR: the two half-adder sums, P1 and P2
- 2× AND: the two half-adder carries; the second is P3
Step by step
- Place inputs
A1,A0,B1,B0and build the four partial products withANDgates. - Column 0:
P0 = A0 AND B0, nothing to add. - Column 1: add
A1B0andA0B1with a half adder. Its sum isP1; keep its carryc1. - Column 2: add
A1B1andc1with a second half adder. Its sum isP2and its carry isP3. - Probe
P3toP0and check a few products: 10 x 11 = 0110 (2 x 3 = 6), 11 x 11 = 1001 (3 x 3 = 9).
2-bit multiplier truth table
| A | B | A x B | P3 P2 P1 P0 |
|---|---|---|---|
| 00 | 00 | 0 x 0 = 0 | 0000 |
| 00 | 01 | 0 x 1 = 0 | 0000 |
| 00 | 10 | 0 x 2 = 0 | 0000 |
| 00 | 11 | 0 x 3 = 0 | 0000 |
| 01 | 00 | 1 x 0 = 0 | 0000 |
| 01 | 01 | 1 x 1 = 1 | 0001 |
| 01 | 10 | 1 x 2 = 2 | 0010 |
| 01 | 11 | 1 x 3 = 3 | 0011 |
| 10 | 00 | 2 x 0 = 0 | 0000 |
| 10 | 01 | 2 x 1 = 2 | 0010 |
| 10 | 10 | 2 x 2 = 4 | 0100 |
| 10 | 11 | 2 x 3 = 6 | 0110 |
| 11 | 00 | 3 x 0 = 0 | 0000 |
| 11 | 01 | 3 x 1 = 3 | 0011 |
| 11 | 10 | 3 x 2 = 6 | 0110 |
| 11 | 11 | 3 x 3 = 9 | 1001 |
Sixteen rows, the largest product being 3 x 3 = 9 (1001), which is why the product needs four bits: an n-bit by n-bit multiplier gives a 2n-bit product. Wider multipliers use the same plan with more partial products and full adders in each column (an array multiplier); every one of the 16 rows here is checked before the page is built.
You can also read the full theory in the lesson on binary multiplication. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
Build more parts from gates
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the 2-bit multiplier in the lab →Frequently asked
How does a 2-bit binary multiplier work?
It forms the four partial products with AND gates (each bit of A times each bit of B), then adds them column by column like long multiplication: P0 = A0B0, column 1 adds A1B0 and A0B1 with a half adder, and column 2 adds A1B1 and that carry with another half adder.
How many gates does a 2-bit multiplier need?
Eight: four AND gates for the partial products and two half adders, each one XOR and one AND.
Why does a 2-bit multiplier need 4 output bits?
The largest product is 3 x 3 = 9, and 9 needs four bits (1001). In general multiplying two n-bit numbers gives up to 2n bits.
How do you build a 4-bit multiplier?
Form all 16 partial products with AND gates and add the shifted rows with adders: three rows of 4-bit adders in an array multiplier. CPUs without a hardware multiplier do the same thing in software with shift-and-add.