Operators in Python | EP-35 Bitwise Operators in Python | Right-shift, Left-shift, AND, OR, NOT, XOR

Published: 04 September 2024
on channel: Cybrosys Technologies
97
2

Python Bitwise Operators

Python bitwise operators are used to perform bitwise calculations on integers. The integers are converted into binary and then operations are performed on each bit. The result will be in decimal format."""

Bitwise AND Operator

The two-bit integers are compared. If both compared bits are 1, then the resulting bit is 1. If not, it is 0.
a=7 #111
b=4 #100
print(a and b)

Bitwise OR Operator

if the both bits are 0 then the result is 0. If not, it is 1.
a=7 #111
b=4 #100
print(a or b)

Bitwise XOR Operator

The Python Bitwise XOR (^) Operator also known as the exclusive OR operator, is used to perform the XOR operation on two operands. If the bits are different, it returns 1;
otherwise, it returns 0.
a=7 #111
b=4 #100
print(a ^ b)

Bitwise NOT Operator

The Python Bitwise Not (~) Operator works with a single value and returns its one’s complement. This means it toggles all bits in the value, transforming 0 bits to 1 and 1 bits to 0, resulting in the one’s complement of the binary number.
a=10 #1010
print(~a)

Bitwise Shift

The bitwise shift operators move the bit values of a binary object. The left operand specifies the value to be shifted. The right operand specifies the number of positions that the bits in the value are to be shifted.

Python Bitwise Right Shift

Shifts the bits of the number to the right and fills 0 on voids left.

Python Bitwise Left Shift

Shifts the bits of the number to the left and fills 0 on voids right as a result.

#PythonTutorial #BitwiseOperators #PythonProgramming #PythonForBeginners #Coding #LearnPython #PythonTips #Programming #python #bitwiseoperators #python3 #python2 #programmingtutorial

Connect With Us:
—————————————
➡️ Website: https://www.cybrosys.com/
➡️ Email: [email protected]
➡️ Twitter:   / cybrosys  
➡️ LinkedIn:   / cybrosys  
➡️ Facebook:   / cybrosystechnologies  
➡️ Instagram:   / cybrosystech  
➡️ Pinterest:   / cybrosys  


Watch video Operators in Python | EP-35 Bitwise Operators in Python | Right-shift, Left-shift, AND, OR, NOT, XOR online without registration, duration hours minute second in high quality. This video was added by user Cybrosys Technologies 04 September 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 97 once and liked it 2 people.