Why bitwise not does not act as expected for toggling bits? See for example below:
a = 5
print(bin(a))
b = ~a
print(bin(b))
This is the output:
0b101
-0b110
The question is why the first bit from the left is not toggled?
Considering that Python documentation says:
~ x Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1.
Edit: Are you saying that "~" is not the operator for simple toggling of bits, but instead it is the operator for twos complement? If so, why the sentence quoted from documentation does not tell that. The sentence above from Python documentation does not imply this to me.