• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

大家帮帮忙~hash << 5 + hash 中的<<是什么意思?该如何处理

php 搞代码 3年前 (2022-01-24) 23次浏览 已收录 0个评论

大家帮帮忙~hash << 5 + hash 中的<<是什么意思?
[code=PHP][/code]static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
{
register ulong hash = 5381;

/* variant with the hash unrolled eight times */
for (; nKeyLength >= 8; nKeyLength -= 8 {
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
hash = ((hash << 5) + hash) + *arKey++;
}
switch (nKeyLength) {
case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough… */
case 1: hash = ((hash << 5) + hash) + *arKey++; break;
case 0: break;
EMPTY_SWITCH_DEFAULT_CASE()
}
return hash;
}

——解决方案——————–
是位移

php移位运算 lz 参考:http://apps.hi.baidu.com/share/detail/23928402
——解决方案——————–

PHP code

$a & $b And(按位与) 将把 $a 和 $b 中都为 1 的位设为 1。$a | $b Or(按位或) 将把 $a 或者 $b 中为 1 的位设为 1。$a ^ $b Xor(按位异或) 将把 $a 和 $b 中不同的位设为 1。~ $a Not(按位非) 将 $a 中为 0 的位设为 1,反之亦然。$a <> $b Shift right(右移) 将 $a 中的位向右移动 $b 次(每一次移动都表示“除以 2”)。
------解决方案--------------------
长见识了……
------解决方案----------------~来1源gaodai#ma#com搞*代#码1网搞代gaodaima码----
是的,但是位移只能做乘除法

探讨

额 非常感谢了 但是还有一个问题~ 恩~以 位 来做相应的运算 有什么好处? 与运算速度有关吗?


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:大家帮帮忙~hash << 5 + hash 中的<<是什么意思?该如何处理
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址