Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这段代码中的 & 符号是什么意思?
int clothes = (random.nextInt(0x1000000) & 0x7f7f7f);
这是按位与运算符。
它独立地对每个位位置进行操作;如果位置n的相应输入位也都为 1,则位置n的输出位仅为1。
在这种情况下,0x7f7f7f被用作位掩码。通过将某些位位置设为 0,这意味着 中的相应位位置clothes将始终为 0。所有其他位位置将采用与 生成的相同的值random.nextInt(0x1000000)。
0x7f7f7f
clothes
random.nextInt(0x1000000)