[英]What does << represent in python?
Python says Python说
1 << 16 = 65536
What operation does <<
performs in Python? <<
在Python中执行什么操作?
It is the left shift operator for Python. 它是Python的左移运算符。 A left shift operation, as the name says, move bits to the left.
正如名称所示,左移操作将位移到左侧。
Suppose you have 2 whose binary representation is 0010. So 2<<2
means to shift the bits twice to the left: 假设您有2的二进制表示为0010.所以
2<<2
表示将位向左移两次:
0010 -> 0100 -> 1000 0010 - > 0100 - > 1000
1000 is the binary representation for 8. Mathematically, left shifting is the same as multiplying a number by a power of 2 : a<<b == a*2^b
, but as the operation is done only by shifting, it is much faster than doing multiplications. 1000是8的二进制表示。数学上,左移与将数乘以2的幂相同:
a<<b == a*2^b
,但由于操作仅通过移位完成,因此比做乘法更快。
This is left shift operator
这是
left shift operator
1<<16
implies 1 to be shifted left by 16 bits. 1<<16
表示1向左移16位。
<<
it's the left-shift operator in Python. <<
它是Python中的左移运算符。 Take a look at the documentation for further details. 请查看文档以获取更多详细信息。
Another way to think about it is 1 times 2^16. 另一种思考方式是1次2 ^ 16。
So whenever you see x << y interpret it as: 所以每当你看到x << y将其解释为:
x * 2^y x * 2 ^ y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.