Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Bitwise-operations/PHP/bitwise-operations.php
Normal file
15
Task/Bitwise-operations/PHP/bitwise-operations.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function bitwise($a, $b)
|
||||
{
|
||||
function zerofill($a,$b) {
|
||||
if($a>=0) return $a>>$b;
|
||||
if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens
|
||||
return ((~$a)>>$b)^(0x7fffffff>>($b-1));
|
||||
|
||||
echo '$a AND $b: ' . $a & $b . '\n';
|
||||
echo '$a OR $b: ' . $a | $b . '\n';
|
||||
echo '$a XOR $b: ' . $a ^ $b . '\n';
|
||||
echo 'NOT $a: ' . ~$a . '\n';
|
||||
echo '$a << $b: ' . $a << $b . '\n'; // left shift
|
||||
echo '$a >> $b: ' . $a >> $b . '\n'; // arithmetic right shift
|
||||
echo 'zerofill($a, $b): ' . zerofill($a, $b) . '\n'; // logical right shift
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue