Is this possible to get the same results in PHP and Javascript?
Example:
Javascript
<script>
function urshift(a, b)
{
return a >>> b;
}
document.write(urshift(10,3)+"<br />");
document.write(urshift(-10,3)+"<br />");
document.write(urshift(33, 33)+"<br />");
document.write(urshift(-10, -30)+"<br />");
document.write(urshift(-14, 5)+"<br />");
</script>
output:
1
536870910
16
1073741821
134217727
PHP
function uRShift($a, $b)
{
if ($a < 0)
{
$a = ($a >> 1);
$a &= 2147483647;
$a |= 0x40000000;
$a = ($a >> ($b - 1));
} else {
$a = ($a >> $b);
}
return $a;
}
echo uRShift(10,3)."<br />";
echo uRShift(-10,3)."<br />";
echo uRShift(33,33)."<br />";
echo uRShift(-10,-30)."<br />";
echo uRShift(-14,5)."<br />";
output:
1
536870910
0
0
134217727
Is this possible to get the same results?
Closest function to what I want is here:
Unsigned right shift function not working for negative input
Thanks for help.