function createHash($string) {
$check1 = $this->stringToNumber($string, 0x1505, 0x21);
$check2 = $this->stringToNumber($string, 0, 0x1003F);
$factor = 4;
$halfFacto开发者_运维知识库r = $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.
>>
means 'Right shift' and the statement you had pointed out - it means
$check1 = $check1 >>$halfFactor
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
It is shift right assignment operator. See this and this.
See documentation (bitwise operators).
This code:
$check1 >>= $halfFactor;
actually means something like that: divide $check1
by 2 ^ $halfFactor
times and assign result to $check1
.
精彩评论