Where did you get the idea that ToInt32(-1) evaluates to 1? It evaluates to -1, which in a 32-bit binary representation with two extra bits is all the bits set to 1. When you use the ~ operator, each bit then becomes 0, which is 0 in 32-bit, two additional binary files .
Representation 1 is all bits 0, with the exception of bit 0. When the bits are inverted, the result is all bits 1, with the exception of bit 0. This occurs as two additional representations of -2. (To see this, simply subtract 1 from the two additional representations -1.)
source share