CSE 271- Signed/Unsigned ComplementsPage 1 of 3

K. Dudeck

Comparison Between Unsigned and Signed 2's Complement

Binary Number Arithmetic (for n=5 bits).

BINARY / DECIMAL EQUIVALENT
UNSIGNED / SIGNED 2's
Range: / 00000 -> 01111
10000 -> 11111 / 0 -> 15
16 -> 31 / 0 -> +15
-16 -> -1
Example
Numbers: / N1=00100
N2=01001
N3=01110
N4=10010
N5=10100
N6=11101 / N1=4
N2=9
N3=14
N4=18
N5=20
N6=29 / N1=+4
N2=+9
N3=+14
N4=-14
N5=-12
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

BINARY / DECIMAL EQUIVALENT
UNSIGNED / SIGNED 2's
Subtract
Examples:
7) N2: 01001 01001
N1: - 00100 -> + 11100
------
1] 00101 1] 00101 / 9
- 4
-----
5 / + 9
- + 4
-----
+ 5
8) N1: 00100 00100
N2: - 01001 -> + 10111
------
0] 11011 0] 11011 / 4
- 9
-----
27 . / + 4
- + 9
-----
- 5
9) N4: 10010 10010
N3: - 01110 -> + 10010
------
1] 00100 1] 00100 / 18
- 14
-----
4 / -14
- +14
-----
+ 4 .
10) N3: 01110 01110
N4: - 10010 -> + 01110
------
0] 11100 0] 11100 / 14
- 18
-----
28 . / +14
- -14
-----
- 4 .
11) N5: 10100 10100
N6: - 11101 -> + 00011
------
0] 10111 0] 10111 / 20
- 29
-----
23 . / -12
- - 3
-----
- 9
12) N6: 11101 11101
N5: - 10100 -> + 01100
------
1] 01001 1] 01001 / 29
- 20
-----
9 / - 3
- -12
-----
+ 9
13) N6: 11101 11101
N1: - 00100 -> + 11100
------
1] 11001 1] 11001 / 29
- 4
-----
25 / - 3
- + 4
-----
- 7
13) N1: 00100 00100
N6: - 11101 + 00011
------
0] 00111 0] 00111 / 4
- 29
-----
7 . / + 4
- - 3
-----
+ 7

. - Overflow

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.
  1. 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).
  1. 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.
  1. 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."
  1. 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."