# Bitwise operators

The Bitwise operators that we can perform in python are:

- Bitwise AND (&)
- Bitwise OR(||)
- Bitwise XOR (^)
- Bitwise NOT (~)

### Bitwise AND (&)

Bitwise AND operator is performed on the bits the bit in the first operand is ANDed with the bit in the second operand. The Bitwise AND operator is performed on all the present. The Bitwise AND operator checks if both the bits are 1 then the result is 1 or the result is 0.

Bitwise OR (||)

Bitwise operator is performed on the bits in which the bit in the first operand is ORed with the bit in the second operand. The Bitwise OR is performed on all the bits present. The Bitwise OR operator check if any one of the bits are 1 and returns 1 if both the bits are 0 then returns 0.

a=15 b=18 c=a&b print(c)

**Output**

2

### Bitwise XOR (^)

Bitwise XOR is performed on the bits in which the bit in the first operand is XORed with the bit in the second operand. The Bitwise XOR operator checks if one of the bits is 1 then returns 1 and if both bits are 0 or 1 then returns 0.

a=17 b=28 c=a|b print(c)

**Output**

29

### Bitwise NOT (~)

Bitwise NOT is a negation operation in which we perform negation on each and every bit present in the operand. If the bit is 1 it is set to 0 if it is 0 then it is set to 1. Bitwise NOT gives the 1's compliment of the given number.

a=15 b=~a print(b)

**Output**

-16

## 0 comments :

## Post a Comment

Note: only a member of this blog may post a comment.