我在苹果的 SpriteKit 示例代码中找到了几行
static const uint32_t missileCategory = 0x1 << 0;
我知道什么static const
是,但什么是 uint32_t
什么是0x1 << 0
意思是?是某种十六进制吗?
最佳答案
<<
是bitwise left shift (乘以 2)运算符。
<< 0
与*1
相同
所以等效语句是:
static const uint32_t missileCategory = 0x1;
我在这方面写了更多 here .
例如:
0x1 << 4
会返回 0x10
.
看它的二进制:
00000001 << 4 = 00010000
十进制这意味着 1 * 2 * 2 * 2 * 2
或 1 * 2^4
因为这是 uint32_t
实际值(value)
0x00000010
关于ios - 请在 Apple SpriteKit 示例代码中解释 uint32_t 和 0x1 << 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20217190/