The original code, complement, anti-code, this thing in the beginning of my study in Java when I bothered me for a while, read the book on the total feeling of weakness what
It boils down to a question: 1000 0101 why not-5?
1) Later looked up the information, their own comb the next, the rationale clearly, in the computer, the system unified use of complement to represent and store, the reason is that through this rule can be signed to participate in the logical operation, so there are the following two rules
① positive: complement = inverse Code = original code
② Negative: complement = inverse code + 1, Inverse code = the positive number corresponding to the negative number of the original code the highest bit take 1
2) The following main explanation of negative number of the complement conversion process, with 5 as an example:
①5 the original code 0000 0101, the highest bit to take 1, get 5 of the original code 1000 0101
② the highest bit unchanged, the other bits take the reverse, get-5 of the anti-code 1111 1010
③ Anti-code + 1, get-5 of the complement 1111 1011, so-5 of the complement is 1111 1011
3) What is 1000 0101 in the previous question? We may as well push down
①1000 0101 is a negative complement, minus 1, to get its inverse code of 1000 0100
② that its original code is the highest bit unchanged, the remaining bits are reversed, get 1111 1011
③ the positive number corresponding to the negative number of the original code is 0111 1011, converted to decimal 2^6 + 2^5 + 2^4 + 2^3 + 2^1 + 1 = 123
So 1000 0101 is 123, not 5, as long as we remember that the negative numbers we see are not real negative numbers, but the complement of negative numbers, to be converted into the original code is its real value
4) We also need to pay attention to several points
①0 's complement is 0000 0000, -128 complement to 1000 0000 (same as -2^15, etc.)
② positive complement + the positive number corresponds to the complement of the negative number = 0000 0000
-5:1111 1011
5:0000 0101
The sum of the two is 0000 0000, which satisfies the mathematical arithmetic logic
Original code, complement, anti-code