Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement: 16 bits: –Example: 4-bit numbers is given by ’ is given by ’
Lecture 9 notes Negative number Sign-magnitude representation 2’s complement Binary addition Binary subtraction
Convert (156) 10 to (?) 2’ 2’s complement representation of positive numbers is the same as sign- magnitude representation. 16 bits example: 156= = 1* * * * 2 2 = ( ) 2 = ( ) 2’
Convert (-156) 10 to (?) 2’ Step 1: ignore the negative sign, obtain the 2’complement of the positive value: (156) 10 = ( ) Step 2: Bitwise inverse: =( ) 2 Step 3: add 1 using binary addition =( ) 2’ done
Remarks Representation of negative number is always associated with the context of total bits With 8 bits, -2 = ( ) 2’ With 16 bits, -2 = ( ) 2’
Binary addition review x Y x y sum bit carry bit Example:
Binary Subtraction When represented in sign-magnitude format, subtraction is performed in a similar way as in the base 10 case. Subtraction uses a different set of `rules’ other than the addition With 2’s complement representation, we can achieve subtraction via binary addition!
Example 7-6 Step 1: get 2’ complement representation for 7 and –6: 7 = ( ) 2’* -6=( ) 2’** Perform binary addition between * and **, we get ( ) Ignore the overflow bit, we have ( ) Done, this is the result of the subtraction represented in 2’s complement format.