Skip to main content

Binary Arithmetic

Every arithmetic operation a processor performs eventually bottoms out in the same handful of bit-level operations covered here. The rules are simpler than decimal arithmetic in every way except one: because there are only two digits, carries happen far more often, and getting comfortable with that is most of what this page is about.

Binary addition​

Binary addition follows the same place-value logic as decimal addition, just with a much smaller digit set — so a carry out of one column happens as soon as a column sums to 2, not 10:

0 1 1 1 (carries)
0 1 1 0 (6)
+ 0 1 0 1 (5)
---------
1 0 1 1 (11)

Column by column, from the right: 0+1=1. 1+0=1. 1+1=10, write 0, carry 1. 0+0+carry 1=1. Result: 1011₂ = 11₁₀ — correct.

This is exactly the operation a full adder implements at the single-bit level (one bit of a, one bit of b, and a carry-in, producing a sum bit and a carry-out) — a circuit you'll build from scratch in a later combinational-logic page in this topic. A binary adder for any bit width is just n full adders, each one's carry-out feeding the next one's carry-in — a ripple-carry adder, named for how the carry ripples down the chain.

Binary subtraction via two's complement​

Digital hardware essentially never implements subtraction as its own operation. Instead, A − B is computed as A + (−B), where −B is B's two's complement (invert every bit, add 1) — from Number Systems & Base Conversion. This is the whole payoff of choosing two's complement in the first place: the same adder circuit does both addition and subtraction, with subtraction just needing an extra inverter stage on one operand and a carry-in of 1 (which supplies the "+1" step of the complement) — no separate subtractor circuit anywhere in the design.

Compute 6 - 5 using 4-bit two's complement:

5 = 0101
-5 = invert(0101) + 1 = 1010 + 1 = 1011

0110 (6)
+ 1011 (-5)
------
1 0001

Discard the carry out of the 4-bit field: result = 0001 = 1 ✓ (6 - 5 = 1)

Discarding the final carry-out is expected and correct here — in fixed-width two's-complement arithmetic, a carry out of the most significant bit during a subtraction that stays within representable range is a normal artifact of the method, not an error. (Contrast this with overflow, covered next, which is a real error condition and looks different.)

Detecting overflow​

Overflow happens when the true mathematical result of an operation falls outside the range an n-bit two's-complement field can represent (-2ⁿ⁻¹ to 2ⁿ⁻¹ − 1). The standard hardware detection rule: overflow occurred if the carry into the sign bit differs from the carry out of the sign bit.

4-bit example: 5 + 4 (both fit individually, sum doesn't)

0101 (5)
+ 0100 (4)
------
1001 (-7 in 4-bit two's complement — wrong! true answer is 9)

Carry into bit 3 (sign bit): 1
Carry out of bit 3: 0
These differ → overflow detected.

Two positive operands producing a result that reads as negative is the classic symptom — the hardware isn't "wrong," it's correctly following the rules of a 4-bit field that simply can't hold 9. This is why real ALUs carry a dedicated overflow flag distinct from the carry flag: the carry flag matters for unsigned arithmetic, the overflow flag for signed, and conflating them is a common source of subtly wrong arithmetic logic.

BCD arithmetic​

Binary-Coded Decimal (covered fully in Digital Codes) represents each decimal digit as its own 4-bit binary group. Adding two BCD digits with ordinary binary addition can produce a result in the range 10–19 that's a valid 4-bit binary number but not a valid BCD digit (BCD only uses 0000–1001). The fix is a correction step: if the 4-bit sum exceeds 9, or a carry out of that nibble occurred, add 0110 (6) to force the result back into valid BCD range and generate the correct carry into the next digit. This correction logic is exactly what a BCD adder adds on top of an ordinary binary adder — useful context for why BCD, despite being less space-efficient than pure binary, still shows up in things like calculators and digital displays where decimal correctness matters more than density.

What's next​

With representation and arithmetic covered, the next page looks at the specialized codes — Gray code, BCD, Excess-3, parity — that digital systems use for reasons other than raw arithmetic efficiency: safe transitions, human-decimal alignment, and error detection.