How does Python’s bitwise complement operator (~ tilde) work?
Remember that negative numbers are stored as the two’s complement of the positive counterpart. As an example, here’s the representation of -2 in two’s complement: (8 bits) 1111 1110 The way you get this is by taking the binary representation of a number, taking its complement (inverting all the bits) and adding one. Two starts … Read more