+ 1

Why this code give output 0 ?

This question is askimg by me in challenge Code is: x = 3 print(x >> 2) https://code.sololearn.com/cC5IPhwr58JM/?ref=app

20th Jun 2019, 5:49 PM
Jitendra
Jitendra - avatar
2 Answers
+ 15
• Multiply by a power of 2 x = x << 1; // x = x * 2 x = x << 6; // x = x * 64 • Divide by a power of 2 x = x >> 1; // x = x / 2 x = x >> 3; // x = x / 8 • https://www.sololearn.com/learn/4087/?ref=app • https://www.sololearn.com/learn/4086/?ref=app
20th Jun 2019, 8:36 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
It's a Bitwise Right Shift. Essentially, you are dividing 3 by 4, and that's why the output is 0, because you are dealing with integers. Try x=12 and the output will be 3. https://www.sololearn.com/learn/4086/?ref=app
20th Jun 2019, 5:56 PM
voja
voja - avatar