Page 1 of 1

Can anyone translate this to english for me

Posted: Tue Dec 29, 2009 3:33 pm
by ellisje22
I am a java programmer, tasked with reverse engineering some PHP code.

Can anyone translate the following function for me into English that I can understand?

Code: Select all

private function _getserver($key) 
    {
        $bucket=((crc32($key)>>16)&0x7fff) % $this->bucketcount;
        $tries=$this->bucketcount;
        
        while($tries)
        {
            $mc=@memcache_connect(get_cfg_var("servername.memcache.ip".($bucket+1)),get_cfg_var("servername.memcache.port".($bucket+1)));
            if($mc)
            {
                return $mc;
            }
            $bucket=($bucket+1)%$this->bucketcount;
            --$tries;
        }
        
        return null;
    }

I am particularly confused by the line:

Code: Select all

$bucket=((crc32($key)>>16)&0x7fff) % $this->bucketcount;

Re: Can anyone translate this to english for me

Posted: Tue Dec 29, 2009 3:46 pm
by AbraCadaver
crc32($key)
calculate the checksum polynomial of 32-bit lengths of $key

>>16
shift the bits 16 steps to the right

&0x7fff
perform a bitwise AND with hex 7fff

%
divide that by $this->bucketcount and return the remainder (modulo)

Finally, assign the result to $bucket