Common four bit Operators:& (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise inverse)
& (Bitwise AND): The corresponding bit is 1 o'clock at the same time, 1 after the & operation, otherwise 0
| (bitwise OR): one of the corresponding bits is 1 o'clock, and after the | operation is 1, and 0 is 0
^ (Bitwise XOR): The corresponding bit is 1 o'clock, the ^ operation is 1, at the same time 0 is 0, and the 1 o'clock ^ operation is also 0
~ (bitwise Reversed): $a + (~ $a) =-1
In a computer, negative numbers are expressed in the form of a positive complement.
Here we need to know three concepts, original code, anti-code and complement.
The original code: an integer, converted into a binary number according to the absolute size, called the original code.
8 The original code is: 0000 0000 0000 0000 0000 0000 0000 1000
Inverse code: The binary number is reversed, the resulting new binary number is called the original binary number of the inverse code. The reverse operation means: 1 change 0, 0 to 1.
8 bitwise inversion: 1111 1111 1111 1111 1111 1111 1111 0111
Complement: The inverse code plus 1 is called the complement. That is, to get a number of the complement, first get the anti-code, and then add the inverse code 1, the resulting number is called the complement.
The complement of a positive number is the same as its original code; the complement of a negative number is the minus 1 of its inverse code.
Anti-code plus 1:1000 0000 0000 0000 0000 0000 000 1001; This will get a positive complement of negative numbers. That's--9.
Reference: http://www.cnblogs.com/setsail/archive/2013/05/22/3093542.html
http://my.oschina.net/WarRome/blog/90707
The above explanation oneself also did not see too understand, but practice obtains $a+ (~ $a) =-1
Here are a few examples:
$m = 8;
$n = 12;
$p =-109;
$mn = $m & $n;
echo $mn. "
";
$mn = $m | $n;
echo $mn. "
";
$mn = $m ^ $n;
echo $mn. "
";
$mn =~ $m;
echo $mn. "
";
$mn =~ $p;
echo $mn. "
";
?>
Output Result:
8
12
4
-9
108
On the issue of bitwise inversion, and then pondering