Adders & Subtractors

Digital Logic 101 · 12 min read

Binary addition rules

ABCinSumCout0000000110010100110110010101011100111111
Figure 1. Single-bit add table. Two operand bits and a carry-in produce a sum bit and a carry-out — exactly what one full-adder cell computes.

One column of binary addition is a full adder: three inputs (A, B, Cin) and two outputs (Sum, Cout). Sum is ABCinA \oplus B \oplus C_{in}; carry-out is the majority of the three inputs.

Half adderHAABSCoutS = A ⊕ BCout = A · BFull adderFAABCinSCoutS = A ⊕ B ⊕ CinCout = majority(A, B, Cin)
Figure 2. Block symbols. The half adder handles the LSB column (no carry-in); the full adder handles every column above it. Chain one HA + (n−1) FAs — or n FAs with the LSB's Cin tied to 0 — to add two n-bit numbers.

The half adder is the stripped-down case: only two inputs (A, B), so its sum is ABA \oplus B and its carry-out is ABA \cdot B. It fits the LSB column where there is no carry coming in from the right.

ABSumCout
Figure 3. Half adder, gate level. One XOR produces Sum and one AND produces Cout. Both inputs feed both gates — the trunks branch via junction dots.
HA1HA2ABCinSumCout
Figure 4. Full adder = HA + HA + OR. Two half-adders chain through the intermediate Sum1, and an OR merges the two intermediate carries (Co1 from HA1, Co2 from HA2) into the final Cout.

Chain N full adders LSB-to-MSB and you have a ripple-carry adder. Carry propagates from cell to cell, and the time to settle is proportional to N — which is why fast ALUs use carry-lookahead instead.

Subtraction = add the negation

4-bitadderA (4 bits)4B (4 bits)44SUBCinSum (4 bits)Cout
Figure 5. One adder, two modes. The subtract control line MUXes inverted B onto the input and forces Cin = 1; the rest of the datapath is unchanged.

AB=A+(B)+1A - B = A + (\sim B) + 1 in any bit width. The XOR gates on the B input invert when subtract = 1, and feeding 1 into the LSB's carry-in completes the negation. Same hardware, two operations.

Two's complement makes the adder sign-agnostic. The bits of 3-3 in 4-bit form (110121101_2) are the same bits a hex dump would show; what changes is whether you read the MSB as a sign bit. The adder doesn't care — it just sums the bits.

Overflow vs. carry-out

CaseABSumCin(into MSB)Cout(out of MSB)V+7 + +1011100011000101−1 + +1111100010000110+5 + −3010111010010110−4 + −5110010110111011V = Cin ⊕ Cout at the MSB column
Figure 6. Two flags, two questions. The Cin / Cout columns are the carry into and out of the MSB (sign-bit) column — not the LSB. Carry-out asks 'did the unsigned sum exceed the register?'; overflow asks 'did the signed sum land on the wrong side of the number line?'

Carry-out is the bit that falls off the MSB during the add. It's the C flag on most CPUs and tells you whether the unsigned sum overflowed 2n2^n.

Overflow is signed: it fires when both operands have the same sign but the result has a different sign. Equivalently, it's CinCoutC_{in} \oplus C_{out} at the MSB.

Carry-out and overflow are independent flags. Use carry for unsigned arithmetic and multi-precision chaining; use overflow for signed-arithmetic correctness. Subtraction is just add-the-inverse with carry-in 1, so the same adder handles both — and both flags still apply.