Bitwise not operator: Returns one’s compliment of the number in Python.
In C, bitwise not operator just flips the bits. So both the languages perform differently.
Q1: Is there an equivalent bit flip operation in Python
Q2: The one's complement of a number is usually the flipped operation. However, in the link for Python, the example includes the opposite sign followed by the result of adding 1 ie. ~x = ~(binary_x) = -(binary_x+1).
This operation based on my understanding is not equal to one's complement as in C. Rather, the not in Python looks similar to 2's complement.
So what is this operation and what is the correct way to do Bitwise NOT ~ in Python?
-(x+1), which is what~does. If that isn't giving you the result you want, you should probably give more detail about what problem you're trying to solve.-in Python is subtraction. But Python integers are quite different from C integers at the bit level.