CSCI 206 Computer Organization Department of Computer Science

  • Slides: 8
Download presentation
CSCI 206 – Computer Organization Department of Computer Science Bucknell University Signed Integers Ch

CSCI 206 – Computer Organization Department of Computer Science Bucknell University Signed Integers Ch 2. 4 This set of notes is based on notes from the textbook authors, as well as Alan Marchiori, L. Felipe Perrone, and other instructors. Xiannong Meng, Spring 2021.

How to actually do add or sub? If the registers rs 1, rs 2,

How to actually do add or sub? If the registers rs 1, rs 2, hold values 3, -2, how does the operation add rd, rs 1, rs 2 work? In general, how does computer do x = 4 + (-3)

How to represent signed numbers? • A 3 -bit system would have 8 different

How to represent signed numbers? • A 3 -bit system would have 8 different values, say, -4 through 3, how do we operate such that 3 + (-2) == 1? -4 -3 -2 -1 ? ? 0 1 2 3 000 001 010 011 • 011 + (? ? ? ) = 001

How to represent signed integers Method 1. Sign Magnitude The leading bit represents the

How to represent signed integers Method 1. Sign Magnitude The leading bit represents the sign, 0 for positive, 1 for negative, followed by the value (magnitude). The following are some values in an 8 -bit number system. 0000 0 1111 -127 00000001 1 11111110 -126 10001001 -9 Problem: What does this represent? 10000000

How to represent signed integers Method 2. 1’s Complement The leading bit represents the

How to represent signed integers Method 2. 1’s Complement The leading bit represents the sign, invert the rest of the bits if a negative value. 0000 0 1111 -0 00000001 1 11111110 -1 00001001 9 Problem: The same problem as sign magnitude. What does 10000000 represent? https: //en. wikipedia. org/wiki/On es%27_complement

How to represent signed integers Method 3. 2’s Complement The leading bit represents the

How to represent signed integers Method 3. 2’s Complement The leading bit represents the sign, invert the rest of the bits if a negative value, and add 1 to the last bit. 0000 0 1111 -1 00000001 1 11111110 -2 11110111 -9 This seems to be a good solution! The pattern 10000000 represents negative 128!

How to represent signed integers 4. Biased (excess) A bias value, B, is usually

How to represent signed integers 4. Biased (excess) A bias value, B, is usually chosen to be roughly in the middle of the range. The actual value x of a bit pattern p is x = p - B. Given x, the bit pattern should be p = x + B. This is useful in some occasions. B = 127 p B = 3 x 0000 -127 1111 128 00000001 -126 11111110 127 1000 9 p x 000 -3 001 -2 010 -1 011 0 100 1 101 2 110 3 111 4

Number Encoding Summary Sign Magnitude first digit is sign (0=positive), remaining digits are magnitude

Number Encoding Summary Sign Magnitude first digit is sign (0=positive), remaining digits are magnitude 1’s Complement first digit is sign, remaining bits are magnitude. Negative numbers are stored inverted. Do activity 2’s Complement Same as 1’st complement, but negative numbers are inverted + 1. Biased redefine zero to be in the middle of the range. The distance from the virtual zero is the magnitude.