لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Lesson 16 B:Bitwise Operators In Python

Bitwise Operators In Python are used to compare (binary) numbers.
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off

Explanation

&

& pronounced as 'AND' Sets each bit to 1 if both bits are 1.

|

| pronounced as 'OR'Sets each bit to 1 if one of two bits is 1.

^

^ pronounced as 'XOR'(exclusive OR) is also known as a 'caret operator (^)' Sets each bit to 1 if only one of two bits is 1.

~

~ it means 'NOT Inverts all the bits.

<<

<< is known as 'Zero fill left 'shift' Shift left by pushing zeros in from the right and let the leftmost bits fall off.

>>

>> is known as 'Signed right shift' Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off.