1 Integer Representations V1.0 (22/10/2005)
2 Integer Representations Unsigned integer Signed integer Sign and magnitude Complements One’s complement Two’s complement Overflow
3 Unsigned integer Represented as binary number 8-bits Unsigned integer representation 0 as 1 as … 254 as 255 as
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 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 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
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 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 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 : – = Same as reversing the bits
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 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 : – =
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 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
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