two's complement logical operation for 32-bit.
$x must be (int) when passing it to this function to work properly.
function comp2($x) // 32bit bitwise complement
{
$mask = 0x80000000;
if ($x < 0)
{
$x &= 0x7FFFFFFF;
$x = ~$x;
return $x ^ $mask;
}
else
{
$x = $x ^ 0x7FFFFFFF;
return $x | $mask;
}
}