大家幫幫忙~hash << 5 + hash 中的<<是什麼意思?該如何處理

來源:互聯網
上載者:User
大家幫幫忙~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 left(左移)    將 $a 中的位向左移動 $b 次(每一次移動都表示“乘以 2”)。$a >> $b    Shift right(右移)    將 $a 中的位向右移動 $b 次(每一次移動都表示“除以 2”)。
------解決方案--------------------
長見識了……
------解決方案--------------------
是的,但是位移只能做乘除法
探討

額 非常感謝了 但是還有一個問題~ 恩~以 位 來做相應的運算 有什麼好處? 與運算速度有關嗎?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.