COMPLEMENTS INTRODUCTION: Basic binary digits are described as UNSIGNED values. This is because if you look at the string of bits (zeros and ones) there is no indicator whether or not this value is positive or negative. You must use an additional symbol "+" or "-" to indicate the sign of the number. There are some types of number systems where you can determine the sign of number without using an addition symbol. You can tell whether it is positive or negative by looking at the bits. Such representations are referred as SIGNED representations because you can determine the sign of the number from the number itself.

In signed representations you the MOST SIGNIFICANT BIT (MSB) indicates the sign of the number. The MSB is the left most bit. If the MSB is equal to 0 then the number is positive. If the MSB is equal to 1 then the number is negative. e. g.

001111101 is positive ^ | The MSB is equal to zero e. g. 101101010 is negative ^ | The MSB is equal to one At this point you might ask yourself why bother with signed representations - we perform decimal based subtractions in every day life using base ten unsigned representations and we " re all happy and well adjusted people. The reason why it's important to learn about signed representations is because when the computer tries to subtract one number Y from another number X, it doesn't do so in the same way that we do: i. e X - Y Instead it uses a technique known as negating and adding: i. e.

X + (-Y) which is still equal to X - Y CONVERSIONS (UNSIGNED BINARY TO SIGNED VALUES) This is summary of what you must do to convert an unsigned binary value to a complemented value. 1's complement 2's complement Binary value > = 0 No change No chang Binary value < 0 Swap the bits Swap the bits and add one to the result. Carry out Add it back in Ignore it Swapping the bits means we substitute 1's for 0's and 0's for 1's. DOING SUBTRACTIONS VIA COMPLEMENTS (ala Negate and Add) How do we do this with the negate and add First convert these numbers to binary: Base 10 Base 2 (must be signed! ) eg 4 0100 -6 -0110 = -2 I added one extra zero to the left hand side as an extra placeholder. When I convert these numbers to signed values, this digit it will represent the sign of the number. We cannot do a mathematical operation in the computer on minus six in this form.

It must be converted to a SIGNED VALUE. You can use either a 2's complement representation or a 1's complement representation. But make sure that you keep straight which one you use (don't switch halfway thru a computation between a 1's and 2's complement representation or vice versa). e. g.

Number to convert 1's complement 2's complement (flip bits) (flip bits + 1) -0110 1001 1010 Add the complemented values with to the original number above (negate and add remember). 1's complement way 2's complement way Number from above (4) 0100 0100 The complemented number 1001 1010 -- -- Summed Result 1101 1110 Convert to this value from a complemented form to regular binary -0010 -0010 Convert from binary -2 -2 to decimal Notice that there is no carry out so we con't have to worry about adding in the overflow or ignoring it. But this conversion only occurs for negative numbers. Look again at the circles that I drew in lab, a positive number is a positive number number matter what binary representation that you use. That means that if the MSB is equal to a zero, when we get to the second last step, when we try to find the equivalent unsigned binary value no conversions are necessary. A positive unsigned digit will look the same in signed (1's and 2's complement form).

Here's another example on complements that does have an overflow bit (carry out): Done using 1's complement: Base 10 Base 2 10 1010 -3 -0011 Now here's comes the fun stage, molding the unsigned base two numbers into signed one's and two's complement representations. Base 2 Add zero to left Convert to 1's complement 1010 01010 01010 0011 00011 11100 Add the numbers 10 + (-3): 01010 +11100 -- Overflow = > 1 00110 Goes here -> +1 -- 000111.