1001 1111 reflect → 0110 0000 add one → 0110 0001
convert to decimal → 26 +25 + 1 = 9710
put sign in front → -9710
The "binary addition algorithm" can be applied to any pair of bit patterns. The adder electonics inside the microprocessor performs this operation with any two bit patterns you send it. You send it bit patterns. It does its job. It is up to you (as the writter of the program) to be sure that the operation makes sense.
Overflow is detected in a different way for each representation. In the following exhibit the "binary addition algorithm" is applied to two bit patterns. Then the results are looked at as unsigned binary and then as two's complement:
Algorithm applied to bit patterns | interpretation of the patterns as unsigned binary | interpretation of the patterns as 2's complement |
---|---|---|
1111 11 0111 0011 1101 0001 --------- 0100 0100 |
11510 20910 ---- 6810 (incorrect) |
11510 -4710 ---- 6810 (correct) |
The "binary addition algorithm" was performed on the operands. The result is either correct or incorrect depending on how the bit patterns are interpreted. If the bit patterns are regarded as unsigned binary integers, then overflow happened. If the bit patterns are regarded as two's comp integers, then the result is correct.
Correct Two's Complement Addition |
---|
When the "binary addition algorithm" is used with operands in two's complement representation: The result is correct if the carry INTO the high order column equals the carry OUT OF the high order column.The carry bits can both be zero or both be one. |