I'm looking for a way to use the >>>
function from JavaScript in the 64-bit version of PHP 5.5.14. I found this function in my googling:
function uRShift($a, $b)
{
$z = hexdec(80000000);
if ($z & $a)
{
$a = ($a >> 1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a >> ($b - 1));
} else {
$a = ($a >> $b);
}
return $a;
}
This function seems to work fine for positive numbers, but I get differing results when passing in negative numbers.
For example:
PHP:
In: echo uRShift(-672461345, 25);
Out: -149
JavaScript (Chrome 35):
In: -672461345 >>> 25
Out: 107
EDIT:
I also tried the other function mentioned in the answer linked above.
function uRShift($a, $b)
{
if($b == 0) return $a;
return ($a >> $b) & ~(1<<(8*PHP_INT_SIZE-1)>>($b-1));
}
PHP:
In: echo uRShift(-672461345, 25);
Out: 549755813867