0

Can someone pls explain what does this operator " << " and " >> "does with example?

a=40>>3 print(a) output = 5 .....how ???? pls explain

19th Apr 2019, 5:11 PM
Abhishek R
Abhishek R - avatar
2 Réponses
+ 4
The operators are called shift operators and work on the bit level, meaning they manipulate the bits a number consists of. There are actually lessons regarding them here on Sololearn, both for right-shifting https://www.sololearn.com/learn/4086/?ref=app and for left-shifting https://www.sololearn.com/learn/4087/?ref=app Maybe they can help you clarify your question.
19th Apr 2019, 5:32 PM
Shadow
Shadow - avatar
+ 3
Left shift and right shift operator, I think you mean. In your example it means move right 3 bits 40. So 2^3 => 8 and 40/8 = 5 is the answer. You can read more here: https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/bitwise_operators_example.htm.
19th Apr 2019, 5:31 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar