+ 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?

1st Jul 2021, 1:21 PM
Zahed Shaikh
Zahed Shaikh - avatar
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)
1st Jul 2021, 1:37 PM
Abhay
Abhay - avatar
1st Jul 2021, 1:37 PM
Jayakrishna 🇮🇳