Computer Arithmetic

binary addition

Binary addition is grade-school column addition, only with two symbols instead of ten. You line the two numbers up by place value and add column by column from the right, carrying a 1 into the next column whenever a column total is too big for a single digit. In base ten you carry when a column reaches ten; in binary you carry when a column reaches two, because two ones make exactly one ten in binary (written 0b10). That single rule, applied across all the columns, is the whole of integer addition in hardware.

For each bit position the hardware adds three things: the bit from the first number, the bit from the second, and the carry coming in from the column to its right. Those three one-bit inputs produce a sum bit (what stays in this column) and a carry-out bit (what flows left into the next column). A circuit that does this for one column is a full adder; chain n of them so each one's carry-out feeds the next one's carry-in and you have an n-bit adder, the workhorse the ALU uses. Worked example: 0b0110 (6) plus 0b0011 (3). Rightmost column 0+1 = 1, no carry. Next 1+1 = 0 carry 1. Next 1+0+carry 1 = 0 carry 1. Next 0+0+carry 1 = 1. Result 0b1001 = 9.

The beautiful part is that this same adder handles signed numbers too, with no changes, because of two's complement representation. The hardware never asks whether a pattern means a positive or a negative number; it just adds the bit patterns and lets the chosen format make the answer come out right. That is precisely why two's complement is the universal integer format and why subtraction can be built from addition rather than needing its own circuit.

Add 0b0110 (6) and 0b0011 (3) column by column from the right: 0+1=1; 1+1=0 carry 1; 1+0+1=0 carry 1; 0+0+1=1. The bits read top to bottom give 0b1001 = 9.

Carry the 1 when a column reaches two, just as you carry at ten in base ten.

If a carry-out leaves the topmost column, the result did not fit in the given width — that is the overflow/carry condition, not a wrong sum. The bits kept are still the correct low bits of the true total.

Also called
二進位相加