当我使用以下变量时,我对两个变量的AND按位运算有问题,因为“ lock” = 1,open = 0
$ACRel = "00000000000000000000010000000000";
// $STS = "11000000011100000000"; //788224 locked
$STS = "11000000001100000000"; //787200 open
echo (is_numeric($STS)&is_numeric($ACRel)); // return 1 or 0
我收到了十进制的$ STS变量,并且我使用decbin()函数进行转换:
$ACRel = "00000000000000000000010000000000";
// $sts = decbin(788224);
$sts = decbin(787200); // return 11000000001100000000
echo (is_numeric($sts)&is_numeric($ACRel));
现在我总是返回1,echo中的decbin返回相同的值,但是当我使用var_dump时,我有:
$sts = "11000000001100000000";
/home/vagrant/code/project/pro/calc.php:8:string '11000000001100000000' (length=26)
$sts = decbin(788224);
/home/vagrant/code/project/pro/calc.php:12:string '11000000001100000000' (length=20)
为什么长度不同,字符串看起来一样?也许这是答案?但我不知道为什么。