What is the complement?#
The complement is using positive numbers to represent negative numbers
Examples#
-
For example, when representing -1 with an 8-bit binary number, only the complement of 1 (00000001) needs to be obtained. The complement is obtained by flipping each digit of 00000001, changing 0 to 1 and 1 to 0, and then adding 1 to the complement result, finally converting to -1 (11111111).
-
Another example, to represent -5, the binary number for 5 is 0101, flipping 0101 and adding 1, it is converted to 1011 (-5).
- Actually, you really don't need to worry about the concepts taught by teachers:
The original, inverse, and complement of positive numbers are the same, while for negative numbers, calculations are required.
Also, everything stored in computers is in complement form, not in original form.
In fact, what computers store are just these numbers, but represented using complements for negative numbers.
Why use complements to represent negative numbers?#
Because all decimal calculations in computers are binary operations, and all subtractions in computers are additions. If complements are not used, then 1-1 would equal -2. For example:
0001-------------(1)
1001-------------(-1)
0001+1001=
1010-------------(-2)
So we use complements to represent negative numbers
0001-------------(1)
1111-------------(-1)
0001+1111=
10000------0000-------(0)
Why is it called a complement?#
Perhaps because when a number is added to its complement, the result is 0. Actually, if you think about it, when representing -5, it is represented using 5, so -5 and 5 are inherently opposite numbers.
Quick tip:#
Since a number and its complement are opposite numbers, complement--->flip+1--->convert to the original number.
-5 (1011)------flip+1-------5 (0101)