Monday 27 May 2019

Bit wise Right Shift operators (>>)


Bitwise Right Shift operators (>>):

If a=10, calculate a>>2 means 2:
This operator shifts the bits of the number towards right a specified number of positions. The symbol for this operator is >>, read it as double greater than. If we write a>>n, the meaning is to shift the bits of a towards right n positions.
Following diagram shows Shifting bits towards right 2 times:










This Operator shifts the bits of the number towards right a specified number of positions. If we write a>>n , means shift the bits of a towards right n positions.

#Example program on all the Bitwise operators
a=10
b=11
print('~a=',~a) #
print('a&b=',a&b)
print('a|b=',a|b)
print('a^b=',a^b)
print('a<<2=',a<<2)
print('a>>2=',a>>2)

"""output
 ==================
~a= -11
a&b= 10
a|b= 11
a^b= 1
a<<2= 40
a>>2= 2
>>>
"""

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...