Bitwise complement Created 2026-10-20 Updated 2026-11-05
The bitwise complement reverses every bit. In an unsigned width- representation, it sends to for : 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- complement in that setting is (~x) & ((1 << w) - 1). The operation is different from Boolean logical negation, which produces a truth value.[ref]https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types. Python documentation, infinite sign-bit convention
Bitwise operation Created 2026-10-20 Updated 2026-11-05
A bitwise operation applies a Boolean operation separately to corresponding positions of binary representations. For four-bit values
1010 and 1100, AND gives 1000, OR gives 1110, and exclusive or gives 0110. Bit shifts move positions, while bitwise complement reverses each bit. The representation width and signedness matter: fixed-width machine arithmetic and unbounded integers need not interpret leading bits alike. These operations are useful for compact sets, flags and bit parallelism. They differ from logical operations that test the truth of entire operands.[ref]https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types. Python language documentation, Bitwise Operations on Integer Types