Bitwise operators
Bitwise operators allow placement of the bits specified in the integer number. If both the left and right arguments are strings, the bitwise operator will manipulate the ASCII value of the character.
Do not move more than 32 bits to the right on 32-bit systems. Do not move left when the result may be more than 32 digits.
Example name result
$a & $b and (bitwise) will set the $a and the bits of the $b 1 to 1.
$a | $b or (bitwise OR) sets the bit 1 in the $a or $b to 1.
$a ^ $b Xor (bitwise exclusive OR) sets the different bits in the $a and $b to 1.
~ $a not (bitwise not) sets the bit of 0 in the $a to 1, and vice versa.
$a << $b shift left (move right) moves the bits in the $a to the left $b times (each time a move is "multiplied by 2").
$a >> $b shift Right (move) moves the bits in the $a to the right $b times (each move is "divided by 2").
<?php Tutorial
$a = 1;
$b = 1;
echo "<br/>and (bitwise AND)"; will set the $a and the $b 1 in the bit to 1
echo $a & $b; Display value 1
echo "<br/>or (bitwise OR)"; will set the $a or the $b to 1 of the bit to 1
echo $a | $b; Display value 1
echo "<br/> Xor (bitwise exclusive OR)"//will set a different bit of $a and $b to 1
echo $a ^ $b; Display value 0
echo "<br/>not (bitwise NOT)"; Set the bit to 0 in the $a to 1, and vice versa
echo ~ $a; Display Value-2
echo "<br>shift left";//Moves the bits in the $a to the left $b times (each time a move is "multiplied by 2")
echo $a << $b; Display Value 2
echo "<br/>shift right";//Moves the bits in the $a to the right $b times (each move represents "divided by 2").
echo $a >> $b; Display value 0
?>
Bitwise operators allow placement of the bits specified in the integer number. If both the left and right arguments are strings, the bitwise operator will manipulate the ASCII value of the character.
<?php
echo 12 ^ 9; Output is ' 5 '
echo "12" ^ "9"; Output fallback characters (ASCII 8)
(' 1 ' (ASCII)) ^ (' 9 ' (ASCII)) = #8
echo "Hallo" ^ "Hello"; Output ASCII value #0 #4 #0 #0 #0
' A ' ^ ' e ' = #4
Echo 2 ^ "3"; Output 1
2 ^ ((int) "3") = = 1
Echo "2" ^ 3;//Output 1
//((int) 2 ") ^ 3 = = 1
?