+ 1

X=5 print (x<<2) I encounter this question under python challenge, the answer was 20, can anyone explain why?

2nd Sep 2020, 7:18 AM
Gbadegesin Muhammed
Gbadegesin Muhammed - avatar
2 Antworten
+ 3
It is binary representation. In binary 5= 0000 0101 Now 5<<2 means, all digits shift 2 positions towards left side. After moves the digits become 0001 0100 is equal to 20 https://www.sololearn.com/learn/4087/?ref=app
2nd Sep 2020, 7:21 AM
Vadivelan
+ 2
Vadivelan thanks for pointing me in the right direction
2nd Sep 2020, 7:26 AM
Gbadegesin Muhammed
Gbadegesin Muhammed - avatar