+ 1

Python

x=3 print(x>>2) output will be 0 Can you please explain me this code?

11th Dec 2021, 8:52 PM
Timofey Ivanenko
Timofey Ivanenko - avatar
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
11th Dec 2021, 9:37 PM
Solo
Solo - avatar
+ 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'))
11th Dec 2021, 9:16 PM
Paul
Paul - avatar
+ 1
Vasiliy , сŠæŠ°ŃŠøŠ±Š¾ Š·Š° Š¾Š±ŃŠŃŃŠ½ŠµŠ½ŠøŠµ!
12th Dec 2021, 7:21 AM
Timofey Ivanenko
Timofey Ivanenko - avatar