+ 2

So, I decided to do some challenge, I was surprised I was been asked shhhh I never seen B4. This one caught my fancy:

x = 5 print (x>>2<<x) I did it on the code playground with the result being 32. Can someone please explain what '<<' and '>>' means?

6th Apr 2020, 12:10 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
4 Respuestas
+ 3
They are Bitwise Operations. Bitwise Left shift and bitwise Right shift. They are covered in Sololearn by the community. Click the links below to learn about them in Sololearn. https://www.sololearn.com/learn/4086/?ref=app https://www.sololearn.com/learn/4087/?ref=app
6th Apr 2020, 12:17 PM
Jolomi Tosanwumi
+ 4
5 >> 2 is 1 1 << 5 is 32.
6th Apr 2020, 12:33 PM
Sonic
Sonic - avatar
+ 1
Since both the operators have the same precedence then according to associativity, we solve from left to right. x>>2 = 5>>2 It means binary 5 has been shifted to right by 2 digits. I'm using 8 bits for representation. 0000 0101 -> 5 0000 0001 -> 1 // after shifting right by 2 digits. So you have the result 1. Now binary 1 is shifted to left by 5 digits because 1<<x which is 1<<5. 0010 0000 -> 32
6th Apr 2020, 12:36 PM
Avinesh
Avinesh - avatar
6th Apr 2020, 1:19 PM
ANJALI SAHU