Loading...
Python

Bitwise Operator

Bitwise Operators are only applicable for int and boolean data type. If we try to apply for any other type then we will get error.
The Bitwise Operator are &, |, ^, ~,<<,>>

print (4&5) ==> valid
print(5.5 & 5.5) ==> TypeError: unsupported operand types for &: ‘float’ and ‘float’

print(True & True) ==> valid

& ==> If both bits are 1 then the result is 1 or else result is 0
| ==> If atleast one bit is 1 then the result is 1 or else result is 0
^ ==> If bits are different then the result is 1 or else 0
~ ==> bitwise complement operator
i.e., the result will be complement
1==>0 and 0==>1

Leave a Reply

Your email address will not be published. Required fields are marked *