Bitwise complement
= Bitwise complement
{title2=$\widetilde x$}
= One's complement
{synonym}
The <bitwise complement> reverses every bit. In an unsigned width-$w$ representation, it sends $x$ to $(2^w-1)-x$ for $0\leq x<2^w$: four-bit `0101` becomes `1010`. Width is essential; without a width there is no finite all-ones mask. Python <integers> instead behave as infinite sign-extended two's-complement values, giving `~x = -x - 1`. A width-$w$ complement in that setting is `(~x) & ((1 << w) - 1)`. The operation is different from Boolean logical negation, which produces a truth value.https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types[Python documentation, infinite sign-bit convention]{ref}