Monday, 24 June 2019

Bit wise Left shift operator (<<)


Bitwise Left shift operator (<<)
>>> a=10
>>> print(a<<2)
40
>>> 
This operator shifts the bits of the number towards a left  specified number of positions. The symbol for this operator is <<, read this as double less-than operator.

If we write a<<n, the meaning is to shift the bits of a towards left n positions.

For example:
If a=10, calculate a value if we write a<<2?

Now we will see how this operator works:
Binary form of 10 is: a=10 à0000 1010

Shifting the value of a towards left 2 positions will make the left most 2 bits to be lost.

If a=10, binary value is 1010
a<<2 means binary value is 0 0 1 0 1 0 0 0 and its decimal number is 40
This operator shifts the bits of the number towards left  a specified number of positions.

Ex2:
a=11, a<<3
>>> a=11
>>> a<<3
88

>>>



Previous Topic: Bitwise Complement (~)



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(...