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