# Bitwise operator in php

by anonymous

• 0
• 0
• 0
83 views
```Orignal Source:http://codingvilla.com/bitwise-operators-php-single-article-589.aspx
Bitwise operator in php:

There are 6 bitwise operators in php.

AND(&),OR(|),XOR(^),NOT(~),Shift left(<<),Shift  right(>>)

In that operation firstly the decimal numbers are converting into binary by dividing that number by 2.

Then common bits of both numbers whose value is 1 are added. The added values are by taking that place value in the base of 2. Bitwise operators operate on bit by bit

And operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "result of and operator";
echo \$x & \$y;
echo "<br/>";
?>

Output:

result of and operator16

OR operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "result of OR operator";
echo \$x | \$y;
echo "<br/>";
?>

Output:

Result of OR operator23Code:

xor operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "result of xor operator";
echo \$x ^ \$y;
echo "<br/>";?>

Output:

result of xor operator7

NOT operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "Not operation of \$x with \$ y is"."".\$x &~ \$y;
echo "<br/>";
?>

Output:

result of not operator1

Shift left operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "result of shift left operator";
echo \$x << \$y;
echo "<br/>";
?>

Output:

result of shift left operator71303168

Shift right operator example:

Code:

<?php
\$x=17;
\$y=22;
echo "result of shift right operator";
echo \$x >> \$y;
?>

Output:

result of shift right operator 0```