filmov
tv
Bitwise Operators in Python (AND, OR, XOR) - Python Tutorial for Beginners

Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ Types of Operators in Python - Bitwise Operators in Python (AND, OR, XOR)
Depending upon the type of operations you want to perform, there are 7 types of operators in Python: Arithmetic operators, Assignment operator, Comparison operators, Logical operators, Bitwise operators, Identity operators and Membership operators.
○ Bitwise Operators in Python
Let's move forward and look at Bitwise Operators, which are similar to Logical Operators but they treat operands as sequences of Binary digits, and operate on them bit by bit. For example, 5 is 101 in binary form, and 7 is 111.
When you perform a OR (|) operation on these operands, it will give you the output 7 (111, in binary form), since you performed a Logical operation on each bit of the numbers, one at a time! This is exactly the same, when you perform the AND (&) operation, but using the appropriate logical operation, bit by bit.
Finally but not least, there is an other bitwise operator in Python, called XOR (^). It performs the exclusive OR operation on each bit of the numbers, and will return True only if one bit is True - not the both of them!
Operator | Meaning | Example
& | Bitwise AND | x & y = 0 (0000 0000)
| | Bitwise OR | x | y = 14 (0000 1110)
~ | Bitwise NOT | ~x = -11 (1111 0101)
^ | Bitwise XOR | x ^ y = 14 (0000 1110)
Apart from these three operators, you have two more bitwise operators, which are right shift, and left shift operators.
What basically happens, when this type of operand is used? First, the value is converted into its binary representation. Then, you will have to specify which type of shift you want to perform, using two greater than signs, or two lesser than signs. Finally, Once you have done that, you will have to specify the number of bits you want to shift! Then, the binary output will shift towards the direction you chose, left or right, for the number of bits you specified.
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
🖥️ Types of Operators in Python - Bitwise Operators in Python (AND, OR, XOR)
Depending upon the type of operations you want to perform, there are 7 types of operators in Python: Arithmetic operators, Assignment operator, Comparison operators, Logical operators, Bitwise operators, Identity operators and Membership operators.
○ Bitwise Operators in Python
Let's move forward and look at Bitwise Operators, which are similar to Logical Operators but they treat operands as sequences of Binary digits, and operate on them bit by bit. For example, 5 is 101 in binary form, and 7 is 111.
When you perform a OR (|) operation on these operands, it will give you the output 7 (111, in binary form), since you performed a Logical operation on each bit of the numbers, one at a time! This is exactly the same, when you perform the AND (&) operation, but using the appropriate logical operation, bit by bit.
Finally but not least, there is an other bitwise operator in Python, called XOR (^). It performs the exclusive OR operation on each bit of the numbers, and will return True only if one bit is True - not the both of them!
Operator | Meaning | Example
& | Bitwise AND | x & y = 0 (0000 0000)
| | Bitwise OR | x | y = 14 (0000 1110)
~ | Bitwise NOT | ~x = -11 (1111 0101)
^ | Bitwise XOR | x ^ y = 14 (0000 1110)
Apart from these three operators, you have two more bitwise operators, which are right shift, and left shift operators.
What basically happens, when this type of operand is used? First, the value is converted into its binary representation. Then, you will have to specify which type of shift you want to perform, using two greater than signs, or two lesser than signs. Finally, Once you have done that, you will have to specify the number of bits you want to shift! Then, the binary output will shift towards the direction you chose, left or right, for the number of bits you specified.
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
Комментарии