Comparision Between Unsigned and Signed 2's Complement



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 | 0 -> 15 | 0 -> +15 |

| |10000 -> 11111 |16 -> 31 |-16 -> -1 |

| |N1=00100 |N1=4 |N1=+4 |

|Example |N2=01001 |N2=9 |N2=+9 |

|Numbers: |N3=01110 |N3=14 |N3=+14 |

| |N4=10010 |N4=18 |N4=-14 |

| |N5=10100 |N5=20 |N5=-12 |

| |N6=11101 |N6=29 |N6=-3 |

|Addition | | | |

|Examples | | | |

|1) |N1: 00100 |4 |+ 4 |

| |N2: + 01001 |+ 9 |+ + 9 |

| |----- |----- |----- |

| |0] 01101 |13 |+13 |

| | | | |

|2) |N2: 01001 |9 |+ 9 |

| |N3: + 01110 |+ 14 |+ +14 |

| |----- |----- |----- |

| |0] 10111 |23 |- 9 . |

| | | | |

|3) |N2: 01001 |9 |+ 9 |

| |N4: + 10010 |+ 18 |+ -14 |

| |----- |----- |----- |

| |0] 11011 |27 |- 5 |

| | | | |

|4) |N3: 01110 |14 |+14 |

| |N5: + 10100 |+ 20 |+ -12 |

| |----- |----- |----- |

| |1] 00010 |2 . |+ 2 |

| | | | |

|5) |N4: 10010 |18 |-14 |

| |N5: + 10100 |+ 20 |+ -12 |

| |----- |----- |----- |

| |1] 00110 |6 . |+ 6 . |

| | | | |

|6) |N5: 10100 |20 |-12 |

| |N6: + 11101 |+ 29 |+ - 3 |

| |----- |----- |----- |

| |1] 10001 |17 . |-15 |

. - Overflow

| |DECIMAL EQUIVALENT |

|BINARY | |

| |UNSIGNED |SIGNED 2's |

|Subtract | | |

|Examples: | | |

| | | |

|7) N2: 01001 01001 |9 |+ 9 |

|N1: - 00100 -> + 11100 |- 4 |- + 4 |

|----- ----- |----- |----- |

|1] 00101 1] 00101 |5 |+ 5 |

| | | |

|8) N1: 00100 00100 |4 |+ 4 |

|N2: - 01001 -> + 10111 |- 9 |- + 9 |

|----- ----- |----- |----- |

|0] 11011 0] 11011 |27 . |- 5 |

| | | |

|9) N4: 10010 10010 |18 |-14 |

|N3: - 01110 -> + 10010 |- 14 |- +14 |

|----- ----- |----- |----- |

|1] 00100 1] 00100 |4 |+ 4 . |

| | | |

|10) N3: 01110 01110 |14 |+14 |

|N4: - 10010 -> + 01110 |- 18 |- -14 |

|----- ----- |----- |----- |

|0] 11100 0] 11100 |28 . |- 4 . |

| | | |

|11) N5: 10100 10100 |20 |-12 |

|N6: - 11101 -> + 00011 |- 29 |- - 3 |

|----- ----- |----- |----- |

|0] 10111 0] 10111 |23 . |- 9 |

| | | |

|12) N6: 11101 11101 |29 |- 3 |

|N5: - 10100 -> + 01100 |- 20 |- -12 |

|----- ----- |----- |----- |

|1] 01001 1] 01001 |9 |+ 9 |

| | | |

|13) N6: 11101 11101 |29 |- 3 |

|N1: - 00100 -> + 11100 |- 4 |- + 4 |

|----- ----- |----- |----- |

|1] 11001 1] 11001 |25 |- 7 |

| | | |

|13) N1: 00100 00100 |4 |+ 4 |

|N6: - 11101 + 00011 |- 29 |- - 3 |

|----- ----- |----- |----- |

|0] 00111 0] 00111 |7 . |+ 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.

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

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download