Why is it that the bitwise NOT operator (~ in most languages) converts the following values like so:
~
-2 -> 1 -1 -> 0
-2 -> 1
-1 -> 0
Most (all?) modern architectures use two's complement to represent signed integers. The bitwise NOT is thus the complement of the integer minus one.