+ 1

How does this code work? print(5>>2) (Python)

print (5>>2) -> Output 1

5th Jan 2025, 4:14 PM
David
David - avatar
4 Respuestas
+ 5
David this code explains the shift right bitwise operator https://sololearn.com/compiler-playground/cc8GLRo2i21c/?ref=app additionally you might like this to explain Binary and bitwise shift left and right ... https://www.sololearn.com/Discuss/2265151/?ref=app
5th Jan 2025, 5:10 PM
BroFar
BroFar - avatar
0
>> 2 means 2 raised to power of two (division) So, it is 5/4 = 1.25. In bit operation, all result must be an integer so you get 1. NOTE >> 3 means 2 raised to power of 3 (division) >> 4 means 2 raised to power of 4 (division) And so on The opposite is multiplication (<<)
5th Jan 2025, 7:33 PM
RuntimeTerror
RuntimeTerror - avatar
0
Output 1
7th Jan 2025, 6:38 AM
Netik Singh
Netik Singh - avatar
0
Output 1
7th Jan 2025, 10:06 AM
Lamborghini
Lamborghini - avatar