C# to PHP - confused

From: Mikee28 Aug 2010 22:20
To: ALL1 of 2
Hi,

Hopefully someone can help a wee bit. I'm attempting to convert a C# class into PHP, but I'm getting stuck on one line..

c# code:
 
int n = x + y * 57;
n = ( n << 13 ) ^ n;
return 1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0;
 
returns 0.992571315728128
 


php code:
 
$n = $x + $y * 57;
$n = ( $n << 13 ) ^ $n ;
return 1 - ( ( $n * ( $n * $n * 15731 + 789221) + 1376312589 ) & 0x7fffffff ) / 1073741824;
 
returns 1
 


where x and y are 78.

Any ideas? I get lost when you start doing all this << >> ^ & rubbish!
From: Mikee28 Aug 2010 22:37
To: ALL2 of 2
php code:
 
echo  Math::int32(1 - ( Math::int32( $n * int32( Math::int32(Math::int32($n * $n) * 15731) + 789221 ) + 1376312589 ) & 0x7FFFFFFF ) / 1073741824 );
 
class Math
{
    public static function int32($value)
    {
        if ($value < -2147483648)
        {
            return -(-($value) & 0xffffffff);
        }
        elseif ($value > 2147483647)
        {
            return ($value & 0xffffffff);
        }
        return $value;
    }
}
 


Christ...

Oh well - sorted.