Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.

Similar presentations


Presentation on theme: "1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s."— Presentation transcript:

1 1 Integer Representations V1.0 (22/10/2005)

2 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s complement  Two’s complement  Overflow

3 3 Unsigned integer Represented as binary number 8-bits Unsigned integer representation  0 as 0000 0000  1 as 0000 0001  …  254 as 1111 1110  255 as 1111 1111

4 4 Unsigned integer arithmetic Same as binary arithmetic For addition, the sum cannot exceed the maximum integer that can be represented For subtraction, the difference must be greater than or equal to 0

5 5 Signed integer Fixed bits => can only represent fixed value of integer Signed integer  Half of the range negative number  Half of the range positive number

6 6 sign and magnitude Use the left most bit for sign ( 0 as positive ;1 as negative) Other bits for magnitude For a 8-bit number +000000000 +100000001 +200000010 +300000011 -010000000 10000001 -210000010 -310000011

7 7 Addition of sign and magnitude Same sign  Add the magnitude  The sum cannot use the sign bit  append the sign bit Different sign (N: negative number, P: positive number)  Turn the N to positive (absolute value of N, abs (N) )  If the abs (N) greater than P Sign bit is 1 (negative) Magnitude is difference of abs (N) - P  If the abs (N) less than P Sign bit is 0 (positive) Magnitude is the difference of P-abs (N)

8 8 Subtraction of sign and magnitude Subtract a positive number  Turn the positive number to negative  Add the magnitude of the two number Subtract a negative number  turn the negative number to positive  add up magnitude of the two number

9 9 Complements (one's complement) If left-most bit is 0, the number is positive; else it is negative To find the negative representation, find its positive representation, then perform one's complement one's complement means subtract number with all 1 with that number For 8-bit number Negative of 0001 1011 : 1111 1111 – 0001 1011 = 1110 0100 Same as reversing the bits +000000000 +100000001 +200000010 +300000011 -011111111 11111110 -211111101 -311111100

10 10 Complements (arithmetic with one’s complement) Subtract positive number  turn the positive number to negative  add up magnitude of the two number subtract negative number  turn the negative number to positive  add up magnitude of the two number Addition  Same as binary addition  For any round-up, add 1 to the answer if absolute sum of two same-signed number is different from magnitude sum, overflow occurs

11 11 Complements (two's complement) If left-most bit is 0, the number is positive; else it is negative To find the negative representation, find its positive representation, then perform one's complement, then add 1 For 8-bit number Negative of 0001 1011 : 1111 1111 – 0001 1011 + 1= 1110 0101 +000000000 +100000001 +200000010 +300000011 11111111 -211111110 -311111101 -411111100

12 12 Complements (arithmetic with two's complement) Subtract positive number  turn the positive number to negative  add up magnitude of the two number subtract negative number  turn the negative number to positive  add up magnitude of the two number Addition  Same as binary addition if absolute sum of two same-signed number is different from magnitude sum, overflow occurs

13 13 overflow For both positive and negative numbers, add the absolute value of the minimum negative number, and represent it as binary number For 8-bit number, it can represent up 256 numbers For signed representation, have 128 positive number and 127 negative number Minimum negative number is -127 For all number represented in this format, add 127 to the number, and represent it as binary number -127 0000000 0 -126 0000000 1 -125 0000001 0 -124 0000001 1 1251111 1100 1261111 1101 1271111 1110 1281111

14 14 arithmetic of overflow Subtract positive number  turn the positive number to negative  add up magnitude of the two number subtract negative number  turn the negative number to positive  add up magnitude of the two number Addition  Same as binary addition if absolute sum of two same-signed number is different from magnitude sum, overflow occurs


Download ppt "1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s."

Similar presentations


Ads by Google