In java ~5=-6, and this -6 is output to the screen, we see -6.
First look at the negation of 5,
The binary source code of 5 is 0000 0 10 1,
The reverse is:11101065438, and the storage prototype of this value in the computer is also1165438. That is to say,1111065438 is a complement.
Complement = original code inversion+1.
The complement to be converted to the corresponding decimal system is
Inverse of original code = complement-1
So1111=111.
So the original code is 1000 0 1 10, and the corresponding decimal system is -6.
Again, look at it this way:
-6 is stored in the form of two's complement in the computer, that is to say, the complement of -6 is100010 (the original binary code of -6 is:10001)