+ 2

What do the operators << and >> do?

For example: x = 3 print (x >> 2)

4th Jun 2019, 11:08 PM
Mariano Rodríguez
Mariano Rodríguez - avatar
3 Respostas
+ 2
Those are shift operators, they shift the bits of the number to the other side and do some stuff, it's complicated to explain that bitwise stuff, so here is how to do it numerically: x<<y = x*(2**y) x>>y = x/(2**y) -The << multiplies first number with 2 power second number -The >> divides first number with 2 power second number EDIT: they will always return an integer(a whole number) so if the result is 0.6 it goes down to 0 in the output
4th Jun 2019, 11:44 PM
Mo Hani
Mo Hani - avatar
+ 6
Left and right shifting of bits.
5th Jun 2019, 4:45 AM
Sonic
Sonic - avatar
+ 1
I get it. Thanks!!
5th Jun 2019, 3:09 AM
Mariano Rodríguez
Mariano Rodríguez - avatar