0101010101010101decimal0101010101010101decimal0101011280164013201160180140121decimal1a = 0b010110112b = 0b001011103bin(a + b)4(200 + 100) & 0xFF544 << 1+
Bit lamps: a lit lamp is a 1, a dark lamp a 0Carry cells: a 1 carried into that columnColumn adder: the sum of one column, in binaryPython card: the same sums typed at the promptTwo bytes added the way you add on paper: the columns line up, worth 128 down to 1, and the work goes from the ones column on the right to the left. A highlighted column shows where the work is. A token carries the column's bits into the column adder; the answer bit drops into the sum row and a carry of 1 climbs to the top of the next column. In hardware, the circuit for one column is called a full adder: three input bits (carry in, a, b) and two outputs (the sum bit and the carry out). Chain eight of them and the carries ripple from right to left, which is called a ripple-carry adder.

Adding bits

  1. Add binary like decimal, one column at a time, but a column holds only 0 or 1. So 1 + 1 = 10: write 0 and carry 1 to the next column. And 1 + 1 + 1 = 11: write 1, carry 1.

Column by column

Checks and limits

Try it in the Python prompt

;; step 1/9 · Adding two bits
>>> bin(0b1 + 0b1)
'0b10'
>>> bin(0b1 + 0b1 + 0b1)
'0b11'
>>> divmod(1 + 1, 2)       # (carry, bit to write)
(1, 0)

In hardware, the circuit for one column is called a full adder: three input bits (carry in, a, b) and two outputs (the sum bit and the carry out). Chain eight of them and the carries ripple from right to left, which is called a ripple-carry adder. Python's int has no fixed size, so 200 + 100 is simply 300. To see what an 8-bit register keeps, mask with & 0xFF (or take % 256). Languages with fixed-size integers, and the CPU itself, wrap around like this.