2
function createHash($string) {
    $check1 = $this->stringToNumber($string, 0x1505, 0x21);
    $check2 = $this->stringToNumber($string, 0, 0x1003F);

    $factor = 4;
    $halfFactor = $factor/2;

    $check1 >>= $halfFactor;
    $check1 = (($check1 >> $factor) & 0x3FFFFC0 ) | ($check1 & 0x3F);
    $check1 = (($check1 >> $factor) & 0x3FFC00 ) | ($check1 & 0x3FF);
    $check1 = (($check1 >> $factor) & 0x3C000 ) | ($check1 & 0x3FFF);  

    $calc1 = (((($check1 & 0x3C0) << $factor) | 
                ($check1 & 0x3C)) << $halfFactor ) | 
                ($check2 & 0xF0F );
    $calc2 = (((($check1 & 0xFFFFC000) << $factor) |
                ($check1 & 0x3C00)) << 0xA) | 
                ($check2 & 0xF0F0000 );

    return ($calc1 | $calc2);
}

>>= what does this expression stand for? it looks very strange to me. I couldn't find any questions on google.

4 Answers 4

2

>> means 'Right shift' and the statement you had pointed out - it means

$check1 = $check1 >>$halfFactor
Sign up to request clarification or add additional context in comments.

Comments

1

It's the equivalent of += for >>.

>> is bitwise shift on a binary level.
If an integer/byte has the value 0000 1000 performing >> 1 on it would make it's new value 0000 0100, it would slide the bits right inserting zeroes to the left.
>> 2 would make it 0000 0010 etc.

The effective result would be the same as dividing it by 4 as >> X == / 2^X

That code is the same as:

$check1 = $check1 >> $halfFactor

Comments

1

It is shift right assignment operator. See this and this.

Comments

0

See documentation (bitwise operators).

This code:

$check1 >>= $halfFactor;

actually means something like that: divide $check1 by 2 ^ $halfFactor times and assign result to $check1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.