Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,9 +1,15 @@
|
|||
function bitwise($a, $b)
|
||||
{
|
||||
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
|
||||
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