we all know some of the operators like arithmetic operators logical operators and now we are going to see bitwise operators

firstly, bitwise operators, we will deal with the bits by these operators we can operate the things like bit array, bit string, or bit numerals.

Secondly, we can use these operators as they are fast In their action and in a simple manner

Coming to the bitwise operator we are having a totally 6 different operators

Operators | Symbols |
---|---|

Complement | ~ |

Or | | |

And | & |

XOR | ^ |

Left shift | << |

Right shift | >> |

## Complement operator

Here we are using the symbol called **~ TILDE **

now let’s try what this operator can do

### To understand this we must know about binary operations with this complementory operators

Generally complement means opposite of it so if we

~1 will gives 0 ~0 will gives 1

## Example

```
a=15
print(~a)
print(bin(a))
```

### Output

-16 0b1111

### Explanation

For 15 we are getting -16how? binary format of 15 is00001111its comlpement will be11110000which will be equal to-16

Is a negative number possible in python? yeah, we can have negative numbers but we should store it as positive numbers,

now how can we do that, there is a concept called as

## 2’s complement

we can find 2’s complement by finding 1’s complement and add 1 to it

for example we will take 2's complement for number 1313 in binary can be written asits complement will be000011011111001for 2's complement +1 ------------ 11110011 which will be equal to12

## Bitwise And operator

And operator will give 1 (true) when both the inputs are 1 (true)

we can understand it with the help of the truth table

**Here for the bitwise and we are using **& (AMPERSAND) Symbol

## Example

```
print(12&13)
```

### Output

12

Now why are we getting 12 as output

to understand that we need to convert into binary format

12 in binary can be written as000011013 in binary can be written as0-------------- 000001100 which will be equal to0000110112

that’s why we are getting 12 as output

## Bitwise OR operator

And operator will give 1 (true) when any one of the inputs are 1 (true)

we can understand it with the help of the truth table

**Here for the bitwise and we are using **| (**pipe**) Symbol

## Example

```
print(12|13)
```

### Output

13

Now why are we getting 13 as output

to understand that we need to convert into binary format

12 in binary can be written as000011013 in binary can be written as0--------------00001101which will be equal to0000110113

that’s why we are getting 13 as output

There is no condition that the output must be one of the given input it can also be any number other than the given numbers

## Example

```
print(45&62)
```

## Output

44

## Explanation

45 in binary can be written as0062 in binary can be written as10110100--------------111110which will be equal to 4400101100

to know more about other operators

- XOR bitwise operator
- left shift bitwise operator
- rightshift bitwise operator