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:
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:
>>>
Ex2:
a=11, a<<3
>>> a=11
>>> a<<3
88
>>>
Related Video: https://www.youtube.com/watch?v=Ui8F9tCTl1U&feature=youtu.be
Next Topic: Bit
wise Right Shift operators (>>)
Previous Topic: Bitwise
Complement (~)
No comments:
Post a Comment