CodingC# to PHP - confused

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mikee  
 To:  ALL
37673.1 
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!
0/0
 Reply   Quote More 

 From:  Mikee  
 To:  ALL
37673.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.
0/0
 Reply   Quote More 

Reply to All    
 

1–2

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats