+ 1
Python
x=3 print(x>>2) output will be 0 Can you please explain me this code?
3 Answers
+ 6
Timofey Ivanenko
This is called a bitwise right shift.
Basically, this is an integer division by 2 to the power of n equal to the number of shifts, that is:
3 >> 2 is 3 // 2Ā² = 0
30 >> 3 is 30 // 2Ā³ = 3
I apologize for the annoying mistake due to haste and as an apology I attach a calculator in which you can perform bitwise operations āŗļø:
https://code.sololearn.com/WW3PS4bq3iGD/?ref=app
+ 4
Run this code, you will see in the binary print that in the second number all bits are pushed two positions to the right. If you do it with 3, it is binary 00000011 if you push the bits two positions to the right it will be 00000000.
x=1136
y = x>>2
print(y)
print(format(x, '016b'))
print(format(y, '016b'))
+ 1
Vasiliy , ŃŠæŠ°ŃŠøŠ±Š¾ Š·Š° Š¾Š±ŃŃŃŠ½ŠµŠ½ŠøŠµ!