+ 1
strange question
Can anyone explain me this? Ive looked into Google but found nothing x=5 print(x>>2) # result is 1 print(x<<2) # result is 20 print(x>>2<<x) # result is 32 i dont get it. What is >> or << ???
5 Answers
+ 8
>> shifts the bits of the binary version of 5 to the right, and << to the left.
so x >> 2 shifts the bits 2 positions to the right.
+ 5
you need to understand binary a bit....
decimal 5 is 00000101in binary
5>>2 is 00000001 which is 1 in decimal
5<<2 is 00010100 thats 16+4 =20
(5>>2)<<5 is 1<<5 , thats 00100000 which is 32 in decimal.
+ 4
A >> n means "divide A by 2, n times" :
A/(2^n)
A << n means "multiply A by 2, n times":
A* (2^n)
+ 2
@ifl now its much clearer. Thanks for help
0
ummmmmmmmmm