80 likes | 245 Views
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’. Lecture 9 notes.
E N D
Negative Number • Sign-Magnitude: left-most bit as the sign bit • 16 bits • Example: 4-bit numbers +510 is given by 01012 -510 is given by 11012 • 2’s complement: 16 bits: • Example: 4-bit numbers +510 is given by 01012’ -510 is given by 10112’
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= 128 + 16 + 8 + 4 = 1* 27+ 1* 24 + 1* 23 + 1* 22 = (0000000010011100)2 = (0000000010011100)2’
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
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’
Binary addition review 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 = (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.