+ 1
How does this code works? Please somebody explain.x=5 print(x>>2<<x)
x=5 print(x>>2<<x) Result: 32 Which operator is this?
2 Réponses
+ 6
shift operator , left shift(<<) and right shift(>>) , used for shifting bits .
5 has a binary value of 101 , so x>>2 will shift it right by two bits which will result in binary value of 1(1 in decimal).
Now we are left with 1<<x which will shift the binary value of 1 left by 5 bits .
So binary value 1 will be become 100000 (32 in decimal)
+ 2
https://www.sololearn.com/learn/4086/?ref=app
https://www.sololearn.com/learn/4087/?ref=app
Hope these lessons helps..