Why is it that the bitwise NOT operator (~
in most languages) converts the following values like so:
-2 -> 1
-1 -> 0
This is because the bit-wise operator literally inverts each bit in the word. It is NOT strictly an arithmetic operation, it is a logic operation.
-2 == %1110, ~-2 == ~%1110 = %0001 == 1 -1 == %1111, ~-1 == ~%1111 = %0000 == 0
and so on.
To go from -2 to 2, and 1 to -1 you need to use the arithmetic negation operation.