PHP中“+”,“ - ”和“^”运算符之间的区别?
问题描述:
Difference between “+”, “-” and “^” operators in PHP?
echo "<br>";
echo 200+233; //433
echo "<br>";
echo 200^233; //33
echo "<br>";
echo 233^20; //253
As you see sometimes '^' works as '-' and sometimes as '+'...
What a rule?
答
This is the XOR operator. It's a binary operator that returns true if both inputs are not the same:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0
So it's looking at the two numbers you have input as binary numbers and comparing each bit and returning a new result:
200 in binary = 11001000
233 in binary = 11101001
result 00100001
That result as a decimal number is 33.