Math Fundamentals18 sections · 814 units
Open in Course

Bitwise NOT (~)

Flip all bits

The NOT operator (~) flips every bit in a number. Every 0 becomes 1, and every 1 becomes 0.

Example: 5\sim5. In 8-bit binary, 5=000001015 = 00000101. Flipping all bits gives 1111101011111010. But here's the catch: computers use signed integers with two's complement representation, so 5=6\sim5 = -6 in most programming languages.

You won't use NOT as often as the other operators, but it's useful when combined with AND to clear specific bits.