CSE 271- Signed/Unsigned Complements K. Dudeck Page 1 of 3 Comparison Between Unsigned and Signed 2's Complement Binary Number Arithmetic (for n=5 bits). BINARY Range: Example Numbers: 00000 -> 01111 10000 -> 11111 N1=00100 N2=01001 N3=01110 N4=10010 N5=10100 N6=11101 DECIMAL EQUIVALENT UNSIGNED SIGNED 2's 0 -> 15 0 -> +15 16 -> 31 -16 -> -1 N1=4 N1=+4 N2=9 N2=+9 N3=14 N3=+14 N4=18 N4=-14 N5=20 N5=-12 N6=29 N6=-3 Addition Examples 1) N1: 00100 N2: + 01001 ----0] 01101 4 + 9 ----13 + 4 + + 9 ----+13 2) N2: 01001 N3: + 01110 ----0] 10111 9 + 14 ----23 + 9 + +14 ----- 9 . 3) N2: 01001 N4: + 10010 ----0] 11011 9 + 18 ----27 + 9 + -14 ----- 5 4) N3: 01110 N5: + 10100 ----1] 00010 14 + 20 ----2 . +14 + -12 ----+ 2 5) N4: 10010 N5: + 10100 ----1] 00110 18 + 20 ----6 . -14 + -12 ----+ 6 . 6) N5: 10100 N6: + 11101 ----1] 10001 20 + 29 ----17 . -12 + - 3 -----15 . - Overflow CSE 271- Signed/Unsigned Complements K. Dudeck Page 2 of 3 DECIMAL EQUIVALENT UNSIGNED SIGNED 2's BINARY Subtract Examples: 7) N2: 01001 N1: - 00100 -> + ----1] 00101 1] 01001 11100 ----00101 9 - 4 ----5 + 9 - + 4 ----+ 5 8) N1: 00100 N2: - 01001 -> + ----0] 11011 0] 00100 10111 ----11011 4 - 9 ----27 . + 4 - + 9 ----- 5 9) N4: 10010 N3: - 01110 -> + ----1] 00100 1] 10010 10010 ----00100 18 - 14 ----4 -14 - +14 ----+ 4 . 10) N3: 01110 N4: - 10010 -> + ----0] 11100 0] 01110 01110 ----11100 14 - 18 ----28 . +14 - -14 ----- 4 . 11) N5: 10100 N6: - 11101 -> + ----0] 10111 0] 10100 00011 ----10111 20 - 29 ----23 . -12 - - 3 ----- 9 12) N6: 11101 N5: - 10100 -> + ----1] 01001 1] 11101 01100 ----01001 29 - 20 ----9 - 3 - -12 ----+ 9 13) N6: 11101 N1: - 00100 -> + ----1] 11001 1] 11101 11100 ----11001 29 - 4 ----25 - 3 - + 4 ----- 7 4 - 29 ----7 . + 4 - - 3 ----+ 7 13) N1: 00100 N6: - 11101 ----0] 00111 00100 + 00011 ----0] 00111 . - Overflow CSE 271- Signed/Unsigned Complements K. Dudeck Page 3 of 3 CONCLUSIONS: When adding or subtracting binary numbers, there is no difference in the binary result between unsigned and signed. The only distinction between the two systems is the decimal interpretation of the result. Binary addition is simply carried out as usual. Binary subtraction is accomplished by taking the two's complement of the subtrahend and adding it to the minuend. The interpretation of the results are shown below: Unsigned Binary Numbers. 1. Only positive numbers exist; therefore the most significant bit is not an indication of sign. 2. When adding, the answer is correct if there is no carry bit generated (ex. 1,2), if a carry is generated, there is an overflow and more bits are needed to represent the result (ex. 4,5). 3. When subtracting, the answer is correct only when a carry bit is generated (ex. 7,12). If the carry bit is cleared, the subtrahend is greater than the minuend which generates a negative result, which is invalid in an unsigned system (ex. 8,10). Signed 2's Complement Binary Numbers. 1. Positive numbers are identified by a most significant bit equal to 0, while negative numbers have most significant bits (MSBs) equal to 1 and with the negative quantity expressed in its 2's complement. The carry bit has no meaning in a signed 2's complement system. 2. When adding, the answer is always correct if the MSBs of the added numbers are different (ex. 3,4). "Adding a positive and negative number can never produce an overflow." If the MSBs are the same and the MSB of the result is different, an overflow has occurred (ex. 2,5). "Adding two positive numbers can not produce a negative result or adding two negative numbers can not produce a positive." 3. When subtracting, the answer is always correct if the MSBs of the subtracted numbers are the same (ex. 8,12). "Subtracting numbers of the same sign can never produce an overflow." If the MSBs are different, and the MSB of the result is different than the minuend, an overflow has occurred (ex. 9,10). "Subtracting a number of different sign from the minuend is like adding a number of the same sign to the minuend, the result must have the same sign as the minuend."