Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why is ~True equal to -2 in python? Are there any other negative operators besides ~?
Why is ~True equal to -2 in python? Are there any other negative operators besides ~?
Because the default value of True is 1.

Invert True, that is, invert 1.

Because python uses signed representations by default.

The binary representation of 1 is 000000 1.

After you take the reverse, it is111111.

As you can see, after inversion, the sign bit changes from 0 to 1 and becomes a negative number.

But 1 is the beginning of the sign bit, and the computer will recognize it as the complement.

Because negative numbers are represented by the complement in the machine, and the complement is converted into the true value as the numerical bit of the complement, that is, every bit except the sign bit is inverted and then 1 is added. 1111110 divided by the sign is 100000 1, plus/kloc-0.