Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

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.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place inputs A1, A0, B1, B0 and build the four partial products with AND gates.
  2. Column 0: P0 = A0 AND B0, nothing to add.
  3. Column 1: add A1B0 and A0B1 with a half adder. Its sum is P1; keep its carry c1.
  4. Column 2: add A1B1 and c1 with a second half adder. Its sum is P2 and its carry is P3.
  5. Probe P3 to P0 and 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

ABA x BP3 P2 P1 P0
00000 x 0 = 00000
00010 x 1 = 00000
00100 x 2 = 00000
00110 x 3 = 00000
01001 x 0 = 00000
01011 x 1 = 10001
01101 x 2 = 20010
01111 x 3 = 30011
10002 x 0 = 00000
10012 x 1 = 20010
10102 x 2 = 40100
10112 x 3 = 60110
11003 x 0 = 00000
11013 x 1 = 30011
11103 x 2 = 60110
11113 x 3 = 91001

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.