- 使用逻辑与运算符(&)来判断某一位是否为1:
$number = 5; $bitPosition = 2; $bitValue = https://www.yisu.com/ask/($number & (1 << $bitPosition)) ? 1 : 0;>
- 使用右移位运算符(>>)来判断某一位的值:
$number = 5; $bitPosition = 2; $bitValue = https://www.yisu.com/ask/($number>> $bitPosition) & 1;
- 使用左移位运算符(<<)来设置某一位的值:
$number = 5; $bitPosition = 2; $number |= (1 << $bitPosition);
- 使用位操作来检查是否为偶数或奇数:
if ($number & 1) { echo '奇数'; } else { echo '偶数'; }