The bitwise NOT (~
) performs a NOT operation on each bit in a value.
~expression
Number
.The truth table for the NOT operation is:
a | NOT a |
---|---|
0 | 1 |
1 | 0 |
1337 (base 10) = 0000010100111001 (base 2)
~1337 (base 10) = 1111101011000110 (base 2) = -1338 (base 10)
A bitwise not on a number results in: -(x + 1)
.
value (base 10) | value (base 2) | return (base 2) | return (base 10) |
---|---|---|---|
2 | 00000010 | 11111100 | -3 |
1 | 00000001 | 11111110 | -2 |
0 | 00000000 | 11111111 | -1 |
-1 | 11111111 | 00000000 | 0 |
-2 | 11111110 | 00000001 | 1 |
-3 | 11111100 | 00000010 | 2 |