无符号右移 ( >>>) 与有符号右移( ) 不同>>,它将在执行右移操作之前将负数转换为正数,以确保结果返回无符号正整数。例如,右移h >>> 20本质上意味着返回 的下限整数h/Math.pow(2,20)。
例如对于您的输入79847235,因为它是一个正数,所以无符号右移和有符号右移都将返回一个正整数。
79847235>>>20将因此 preform:
Math.floor(79847235/Math.pow(2,20))which 返回76.
接下来h >>> 12是79847235:
Math.floor(79847235/Math.pow(2,12))which 返回19493
(它更大,因为我们除以一个较小的数字)。
现在我们执行一个exclusive ORon76和19493。
例如1^0is1
1^1如果0
我们想要包含 AND,我们必须使用包含 OR,即 |
因此1|1is 1
1|0is 0
etc is the binary
representation
1001100of 76
100110000100101is the binary representation
of 19493
an operationexclusive OR看起来
像这样
000000001001100::
这与:
填写我们的值is : is重要的是要记住我们的新值现在是
下一行: is76
10011000010010119493
---------------
10011000110100119561
h ^= (h >>> 20) ^ (h >>> 12);
h ^= 19561
h = h^19561
h79847235
79847235^1956179827754
h = 79827754
h 79827754
return h ^ (h >>> 7) ^ (h >>> 4);
h>>>7Math.floor(79827754/Math.pow(2,7))哪个返回623654
h>>>4就是Math.floor(79827754/Math.pow(2,4))哪个返回4989234
现在括号已经不碍事了:
return h ^ 623654 ^ 4989234;
从左到右执行这个很重要。
填写h并重新组合:
return (79827754 ^ 623654) ^ 4989234;
79827754 ^ 623654is:
100110000100001001100101010( 79827754in binary)
000000010011000010000100110( 623654in binary)
---------------------------
100110010111001011100001100( 80451340in binary)
最后我们有:
return 80451340 ^ 4989234;
80451340 ^ 4989234is:
100110010111001011100001100( 80451340in binary)
000010011000010000100110010( 4989234in binary)
---------------------------
100100001111011011000111110( 76002878in binary)
因此我们的最终结果是:
return 76002878;
随意检查我的答案,我已经仔细检查了我的工作。
由于按位异或的性质,很难预测散列函数的结果是大于还是小于我们的参数。例如:
11^2is 9(小于我们的参数 11)
17^2is 19(大于我们的参数 17)