Possible Duplicate:
What does this ~ operator mean here?
Bit not operation in PHP(or any other language probably)
谁能解释一下 PHP 中的 ~
运算符?我知道是 NOT-operator ,但是为什么PHP会将下面的语句转换为变量的负值减一呢?
$a = 1; echo ~$a // echo -2
$a = 2; echo ~$a // echo -3
$a = 3; echo ~$a // echo -4
最佳答案
这称为二进制补码运算。你可以阅读它in more detail here .
运算符 ~
是一个二元取反运算符(与 bool 取反相反),正因为如此,它会反转其操作数的所有位。二进制补码计算结果为负数。
关于php - ~ 位运算符(波浪号)的作用是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9129744/