这是什么意思每个代码

-29 struct ios sprite-kit swift swift2

struct Physics {
    static let smallCoin : UInt32 = 0x1 << 1
    static let smallCoin2 : UInt32 = 0x1 << 2
    static let ground : UInt32 = 0x1 << 3
}
Run Code Online (Sandbox Code Playgroud)

那是什么意思

UInt32 = 0x1 << 1?

和静态让?

Mik*_*son 5

<<是左移算子.您可以更好地以二进制形式显示它:

   1        0000 0001
<< 1                ^ shift this one bit to the left
----  =     ---------
   2        0000 0010


   1        0000 0001
<< 2                ^ shift this two bits to the left
----  =     ---------
   4        0000 0100


   3        0000 0011
<< 2                ^ shift this two bits to the left
----  =     ---------
  12        0000 1100
Run Code Online (Sandbox Code Playgroud)

要记住的另一个属性是x << n = x * (2^n).相反的<<>>- 右移操作员.