Computing Library › Digital Logic & Circuits
Digital Logic & Circuits
Full Adder
A full adder sums three bits, two operands plus a carry-in, giving a sum and a carry-out, and is the building block of wider adders.
What it does
A full adder adds three one-bit inputs: operands A and B and a carry-in Cin. It produces a sum S and a carry-out Cout. Chaining full adders lets each bit column accept the carry from the column below it.
Logic
The sum is S = A XOR B XOR Cin. The carry-out is Cout = (A AND B) OR (Cin AND (A XOR B)). A full adder can be built from two half adders and an OR gate: one half adder combines A and B, the second adds Cin, and the OR merges the two carry signals.
Truth table
| A | B | Cin | S | Cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Why it matters
Every general-purpose adder, and by extension the arithmetic in an ALU, is composed of full adders. The way carries propagate between them sets the speed of addition.
In code
python
s = a ^ b ^ cin
cout = (a & b) | (cin & (a ^ b))