Python - Why is result 32? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Python - Why is result 32?

x = 5 print(x>>2<<x)

14th Oct 2019, 11:41 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Answers
+ 7
x>>2 0000_0101 (5) >> (shifted 2 places to the right) = 0000_0001 (1) 1<<5 0000_0001 (1) << (shifted 5 places to the left ) = 0010_0000 (32) The operator is a bitwise shift. New binary places are set to 0.
14th Oct 2019, 12:22 PM
Lothar
Lothar - avatar
+ 3
Quite difficult, but now I understand!
14th Oct 2019, 12:26 PM
Paolo De Nictolis
Paolo De Nictolis - avatar