CISC P81 - Binary Sums: An example. Problem: Compute the binary

advertisement
CISC P81 - Binary Sums: An example.
Problem: Compute the binary sum shown below.
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
We tackle this problem by working from the rightmost column towards the leftmost. I’ll call the sum of
the bits in an individual column a partial sum, because each contributes to the entire sum of the two 8bit numbers.
The first partial sum is 1 + 0 = 1. Easy enough, and works in any number base from binary on up.
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
1
The next partial sum is a little more tricky for people new to binary notation, since we instinctively know
one plus one equals two, but there is no “2” digit in binary. Two, written in binary, is “10”. So, we write
down the “0”, and carry the “1” into the third column. (A CPU’s arithmetic circuitry has special memory
devices to handle these carried bits.)
1
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
0 1
Thus, the next partial sum to compute is 1 + 1 + 1. Again, we’re faced with a situation where the binary
sum doesn’t fit in a single binary digit, since the value we call three is written “11” in binary. So the
partial sum is 1 with a carry of 1 into the next column.
1
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
1 0 1
The next partial sum, of 1 + 0 + 0, is straightforward, and there’s nothing to carry into the next column.
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
1 1 0 1
And now we’re back to adding 1 + 1 again, so the partial sum is 0 with a carry of 1.
1
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
0 1 1 0 1
1 + 1 + 0 gives us another partial sum of 0, carry 1.
1
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
0 0 1 1 0 1
1 + 0 + 1 gives us yet another partial sum of 0, carry 1.
1
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
0 0 0 1 1 0 1
And finally, 1 + 0 + 0 gives us a partial sum of 1 with no carry.
0 0 1 1 0 1 1 1
+ 0 1 0 1 0 1 1 0
1 0 0 0 1 1 0 1
As this is an 8-bit representation, if there had been a carry out of this leftmost column, and this were a
real CPU with 8-bit registers, the extra carry would likely have ended up in a special CPU register called an
overflow bit.
To check this, you can convert the values in the original problem into decimal, add them together, then
convert the binary sum, above, into decimal and see if the two decimal sums are the same.
Download