|
What is complementing?
Basically, the idea of complementing arose from a very simple observation based on the question: Which mathematical operation is simpler:
How ??? Let's first take a look at complementing in decimal (base 10). Here are some complementary values:
So what ??? We can either subtract a number from another number, or add the complement of that number. For example:
What does this have to do with binary ??? In binary, complement complements are very easy to determine. For example:
This is known as One's Complement. Basically, it means that whenever we find a '0', we change it to a '1'; Whenever we find a '1', we change it to a '0'. Let's go back to our previous example. Now If we add +56 and -56, we get: But that is not the value 0 (zero) !!! Actually, it is. First, look at the sign bit (the left-most bit). Notice that is '1' (meaning the value stored is negative). Because negative values are stored as complemented values (or in the case of binary, the opposite of the number), to make sense of the value, we once again need to complement (change the '0's to '1' and the '1's to '0'): And the final value turns out to be -0 (negative zero). Negative zero !!! How is that possible ??? Actually, zero is neither negative nor non-negative. We could have either a +0 or a -0 (or both). Is there any way to get rid of negative zeros ??? Yes. We need to slightly modify the process and use two's complement. That, however, will be our next tutorial. Some good references to help you better understand complementing include:
Some questions you should be able to answer:
Answers:
|