Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 210 Computer Organization

Similar presentations


Presentation on theme: "Computer Science 210 Computer Organization"— Presentation transcript:

1 Computer Science 210 Computer Organization
Number Systems Signed Integers

2 Negatives: Sign-Magnitude
With a fixed number of bits, say N The leftmost bit is used to give the sign 0 for positive number 1 for negative number The other N-1 bits are for the magnitude Example: -25 with 8 bit numbers Sign: 1 since negative Magnitude: for 25 8-bit result: Note: This would be 153 as a positive.

3 Ranges for N-bit numbers
Unsigned (positive) 0000… or 0 1111… which is 2N-1 For N=8, Sign-magnitude 1111…11 which is -(2N-1-1) 0111…11 which is 2N-1-1 For N=8, -127 to 127 2’s Complement 1000…00 which is -2N-1 0111…11 which is 2N For N=8, to 127

4 Sign-Magnitude: Pros and Cons
Easy to comprehend Easy to convert Con: Addition complicated (expensive) If signs same then … else if positive part larger … Two representations of 0

5 Negatives: Two’s complement
With N bit numbers, to compute negative Invert all the bits Add 1 Example: -25 in 8-bit two’s complement 25  Invert bits: Add 1:

6 2’s Complement: Pros and Cons
Not so easy to comprehend Human must convert negative to identify Pro: Addition is exactly same as for positives No additional hardware for negatives, and subtraction. One representation of 0

7 2’s Complement: Examples
Compute negative of -25 (8-bits) We found -25 to be Invert bits: Add 1: Recognize this as 25 in binary Add -25 and 37 (8-bits) (-25) ( 37) (1) Recognize as 12

8 Facts about 2’s Complement
Leftmost bit still tells whether number is positive or negative as with sign-magnitude 2’s complement is same as sign magnitude for positives

9 2’s complement to decimal (examples)
Assume 8-bit 2’s complement: X = X = = = = 39 (decimal) So, X = -39 X = Since X is positive, we have X = = 89


Download ppt "Computer Science 210 Computer Organization"

Similar presentations


Ads by Google