Python Bitwise NOT Operator (~)
Bitwise NOT Operator
Bitwise NOT Operator is used to perform NOT operation for the given operand at bit level.
Symbol
The symbol of bitwise NOT operator is ~.
Syntax
The syntax to do bitwise NOT operation for the operand x is
~ xExample
The following is a simple example of how bitwise NOT operation is done for a number.
x = 5
#bit level
x = 00000101
~ x = 11111010
~ x = -00000110 (in signed form)
Therefore ~x = -6 (in signed form)In this following program, we take an integer value in x, and perform bitwise NOT operation for the value in x.
Python Program
x = 5
output = ~x
print(f'~{x} = {output}')Output
~5 = -6Summary
In this tutorial of Python Examples, we learned about Bitwise NOT Operator, and it's usage with the help of examples.