Negatives, Addition, Subtraction Binary Negatives, Addition, Subtraction
Storing Negative Integers Another method is 2s Complement -75 64 32 16 8 4 2 1 128 -128 1 1 1 1 1 -128+32+16+4+1=-75
2s Complement Conversion -117 Stage 1 : work out 117 in binary 128 64 32 16 8 4 2 1 Stage 2 : Reverse the 0’s and 1’s -128 64 32 16 8 4 2 1 1 Stage 3 : Plus 1
Binary Addition In binary these are the possible sums… 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0, carry 1 1 + 1 + 1 = 1, carry 1 1 + 1 + 1 + 1 = 0, carry 0, carry 1
Binary Addition Example 1 75 + 14 = 89 128 64 32 16 8 4 2 1 75= 14= Carry 89 1 1 1 1 1 1 1
Binary Addition Example 2 79 + 57 = 136 128 64 32 16 8 4 2 1 79= 57= Carry 136 1 1 1 1 1 1 1 1 1
Binary Addition Example 3 75 + 75 = 150 128 64 32 16 8 4 2 1 75= Carry 150 1 1 1 1 1 1 1 1
Binary Addition Example 4 128 64 32 16 8 4 2 1 26 138 87 251 Carry 1 1 1 1 1 1 1 1 1 1 1
Binary Addition Example 5 128 64 32 16 8 4 2 1 109 39 45 Carry 1 1 1 193 1 1 1 1 1 1
Binary Addition Example 6 128 64 32 16 8 4 2 1 151 42 31 Carry 1 1 1 224 1 1 1 1 1 1
Binary Subtraction CPUs can’t subtract, they can only add! 75-14=61 The same as… 75+(-14)=61 Positive + Negative = Negative To do this we need 2s Complement -128 64 32 16 8 4 2 1
Binary Subtraction Example 1 75-14=61 75+(-14)=61 -128 64 32 16 8 4 2 1 75= -14= 61 1 1 1 1 1 1 1 1
Binary Subtraction Example 2 91-18=73 91+(-18)=73 -128 64 32 16 8 4 2 1 91= -18= 73 1 1 1 1 1 1 1 1 1 1