Home  >  Article  >  Backend Development  >  关于PHP二进制流 逐bit的低位在前算法(详解)_php技巧

关于PHP二进制流 逐bit的低位在前算法(详解)_php技巧

WBOY
WBOYOriginal
2016-05-17 09:01:391008browse
复制代码 代码如下:

  /******************************************************
     * 逐bit的低位在前算法
     * @param $x
     * @return int
     */
    function reverse($x)
    {
        $result = 0;
        for($i = 0; $i         {
            $result = ($result > $i));
        }
        return $result & 0xff;
    }

调用展示:
复制代码 代码如下:

$testData = 0xC5; //二进制:1100 0101
$testRet = reverse($testData);
echo $testRet; //输出值为163,二进制为1010 0011
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn