Presentation is loading. Please wait.

Presentation is loading. Please wait.

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:

Similar presentations


Presentation on theme: "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:"— Presentation transcript:

1 Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers +5 10 is given by 0101 2 -5 10 is given by 1101 2 2’s complement: 16 bits: –Example: 4-bit numbers + 5 10 is given by 0101 2’ -5 10 is given by 1011 2’

2 Lecture 9 notes Negative number Sign-magnitude representation 2’s complement Binary addition Binary subtraction

3 Convert (156) 10 to (?) 2’ 2’s complement representation of positive numbers is the same as sign- magnitude representation. 16 bits example: 156= 128 + 16 + 8 + 4 = 1* 2 7 + 1* 2 4 + 1* 2 3 + 1* 2 2 = (0000000010011100) 2 = (0000000010011100) 2’

4 Convert (-156) 10 to (?) 2’ Step 1: ignore the negative sign, obtain the 2’complement of the positive value: (156) 10 = (0000000010011100) Step 2: Bitwise inverse: =(1111111101100011) 2 Step 3: add 1 using binary addition =(1111111101100100) 2’ done

5 Remarks Representation of negative number is always associated with the context of total bits With 8 bits, -2 = (11111110) 2’ With 16 bits, -2 = (1111111111111110) 2’

6 Binary addition review x Y 10 101 010 x y 10 110 000 sum bit carry bit 0100101 +1001101 1110010 Example:

7 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!

8 Example 7-6 Step 1: get 2’ complement representation for 7 and –6: 7 = (00000111) 2’* -6=(11111010) 2’** Perform binary addition between * and **, we get (1 00000001) Ignore the overflow bit, we have (00000001) Done, this is the result of the subtraction represented in 2’s complement format.


Download ppt "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:"

Similar presentations


Ads by Google