php - PHP && 给出错误答案
问题描述
我正在将一些 VB 代码转换为 PHP,并且在一行中有一个逻辑运算符 AND。
PHP 和 VB 给了我不同的结果,所以分解每一步,它归结为逻辑运算符 AND,或者 &&,就像它在 PHP 中一样。
在 PHP 中,我有:
($intAscii && $a)
$intAscii = 87
具有和的值$a = 128
。
上面的逻辑应该返回 0,但 PHP 返回 1。
将这些转换为二进制:
87 = 01010111
128 = 10000000
所以很明显这应该返回0,那么为什么PHP坚持要返回1呢?
完整功能在这里:
Function IsBitSet($intAscii , $intBit) {
//'change the value of the integer passed by
//'turning on the bit passed
$a=(int)(pow(2 ,(int)$intBit));
$b=($intAscii && $a);
echo '</br>Manual AND 87 && 128 '.(87 && 128) .'</br>';
echo 'is bit set $intAscii='.$intAscii .' $a='.$a.' And = '.( $b).'</br>';
Return(($intAscii && $a) <> 0);
}
和输出:
Manual AND 87 && 128 1
is bit set $intAscii=84 $a=128 And = 1
解决方案
推荐阅读
- python - 使用Python selenium xpath如何获取网站信息,获取六大洲,国家人口排名按数字降序排列
- json - jmeter:我想从 2 个不同的 json 对象中提取 2 个值,其中 1 个 json 对象将验证我的条件和我想提取的其他值
- matlab - Matlab的音频插件参数总是滑块?
- spring-boot - 向 Eureka 服务器注册 Zipkin
- android - 使用 Kotlin 语言在 Android Studio 中为文本设置渐变颜色
- reactjs - ReactComponent 与 type 'IntrinsicAttributes & { children?: ReactNode; 没有共同的属性。}' 使用路由渲染时
- excel - 使用 vba 更改单词自定义字段的值
- python-3.x - 我运行此代码并收到以下错误。我该如何解决?
- kubernetes - Helm 升级自定义微服务导致临时停机
- node.js - 无法停止记录所有在应用程序中触发的 mongoose 查询