请解释php代码返回($ h& 0x0F)<< 12 | (ord($ c {1})& 0x3F)<< 6 | (ord($ c {2})& 0x3F);

时间:2013-12-10 16:54:13

标签: php unicode

我需要了解下面的这个php函数

function uniord($c) {
    $h = ord($c{0});
    if ($h <= 0x7F) {
        return $h;
    } else if ($h < 0xC2) {
        return false;
    } else if ($h <= 0xDF) {
        return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
    } else if ($h <= 0xEF) {
        return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
                                 | (ord($c{2}) & 0x3F);
    } else if ($h <= 0xF4) {
        return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
                                 | (ord($c{2}) & 0x3F) << 6
                                 | (ord($c{3}) & 0x3F);
    } else {
        return false;
    }
}

我对此一无所知:

return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);

什么是&amp; &LT;&LT;和|

由于

1 个答案:

答案 0 :(得分:2)

http://www.php.net/manual/en/language.operators.bitwise.php

&  And           Bits that are set in both $a and $b are set.
|  Or            Bits that are set in either $a or $b are set.
<< Shift left    Shift the bits x steps to the left