CMPBIN

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

CSE 271- Signed/Unsigned Complements K.

Dudeck 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 N1: 00100 N2: + 01001 ----0] 01101 N2: 01001 N3: + 01110 ----0] 10111 N2: 01001 N4: + 10010 ----0] 11011 N3: 01110 N5: + 10100 ----1] 00010 N4: 10010 N5: + 10100 ----1] 00110 N5: 10100 N6: + 11101 ----1] 10001

Page 1 of 3

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 4 + 9 ----13 9 + 14 ----23 9 + 18 ----27 14 + 20 ----2 . 18 + 20 ----6 . 20 + 29 ----17 . + 4 + + 9 ----+13 + 9 + +14 ----- 9 . + 9 + -14 ----- 5 +14 + -12 ----+ 2 -14 + -12 ----+ 6 . -12 + - 3 -----15

1)

Addition Examples

2)

3)

4)

5)

6)

. - Overflow

CSE 271- Signed/Unsigned Complements K. Dudeck

Page 2 of 3

BINARY Subtract Examples: 7) N2: 01001 N1: - 00100 -> + ----1] 00101 1] N1: 00100 N2: - 01001 -> + ----0] 11011 0] N4: 10010 N3: - 01110 -> + ----1] 00100 1] 01001 11100 ----00101 00100 10111 ----11011 10010 10010 ----00100 01110 01110 ----11100 10100 00011 ----10111 11101 01100 ----01001 11101 11100 ----11001

DECIMAL EQUIVALENT UNSIGNED SIGNED 2's

9 - 4 ----5 4 - 9 ----27 . 18 - 14 ----4 14 - 18 ----28 . 20 - 29 ----23 . 29 - 20 ----9 29 - 4 ----25 4 - 29 ----7 .

+ 9 - + 4 ----+ 5 + 4 - + 9 ----- 5 -14 - +14 ----+ 4 . +14 - -14 ----- 4 . -12 - - 3 ----- 9 - 3 - -12 ----+ 9 - 3 - + 4 ----- 7 + 4 - - 3 ----+ 7

8)

9)

10) N3: 01110 N4: - 10010 -> + ----0] 11100 0] 11) N5: 10100 N6: - 11101 -> + ----0] 10111 0] 12) N6: 11101 N5: - 10100 -> + ----1] 01001 1] 13) N6: 11101 N1: - 00100 -> + ----1] 11001 1] 13) N1: 00100 N6: - 11101 ----0] 00111

00100 + 00011 ----0] 00111

. - Overflow

CSE 271- Signed/Unsigned Complements K. Dudeck CONCLUSIONS:

Page 3 of 3

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

You might also like