How do bitwise operations work in Python?
Assuming that values are 32 bits, 10 is
00000000000000000000000000001010
and if you invert all those bits, you get
11111111111111111111111111110101
or -11. Because it's a 2's complement system!
11011
is not -11. You have a misunderstanding of the encoding scheme for negative numbers.
In two's complement, -11 is 10101
which is the correct bit inversion.
To negate a two's complement number, you invert all bits and add one:
01011 eleven
10100 invert
10101 add one gives negative eleven