Exercise 1: Adding in binary, column by column
Binary addition has exactly four one-bit cases: , , , and , which writes a and carries a into the next column on the left. Everything else is that rule repeated. The layout below shows the weights of an 8-bit word above the columns, so that every answer can be checked in decimal without redoing the addition.
- a) Add on 8 bits. Fill in the carry row, then check your result in decimal.
- b) Add . What happens if the machine only has 4 bits for the result?
- c) Add the three numbers in one column layout. What is different about the carries?
- d) Add and confirm the sum by weights rather than by decimal conversion.
- e) A carry can travel across the whole word. Give the 8-bit pair that makes the chain as long as possible, and say what that costs a real adder circuit.
Show the solution
a) Work right to left. Column of weight 1: , no carry. Weight 2: , write and carry . Weight 4: , write , carry . Weight 8: , write , carry . Weight 16: , write , carry . Weight 32: , write , carry . Weight 64: , no carry. Weight 128: . Result . Decimal check: and , so the sum must be ; and . Two independent routes agree, which is the whole point of writing the weights above the columns.
b) and adding gives , which needs five bits. On a 4-bit register the stored result is and the fifth bit leaves the adder as a carry out. The value is not lost because the adder failed; it is lost because nobody kept the carry. This is the difference between the arithmetic, which is always right, and the storage, which has a width.
c) , , , so the sum is . Verify: weight 1 column has three s, that is , so write and carry ; weight 2 has plus the carry, that is again. With three operands a column can produce a carry of , not just , so a carry may have to jump two columns. That is exactly why hardware adds numbers two at a time rather than in one wide gulp.
d) . Align on the right: has weights and has . Adding the weights gives , and . The posed addition gives the same: the two s of weight 1 make a carry into weight 2, which then meets , carries again, and the carry ripples all the way to weight 32. Checking by weights is the faster control here because the answer is a single power of two, which is instantly recognisable.
e) The longest chain is : the carry born in the rightmost column is regenerated by every column it enters and only stops after leaving the leftmost one. The sum is . In a ripple-carry adder each column has to wait for the previous carry, so the delay of the whole circuit is set by this worst case and grows with the word width. That is the reason processors use carry-lookahead adders, which compute the carries in parallel from the operand bits instead of passing them along.