Home  >  Article  >  php教程  >  关于PHP二进制流 逐bit的低位在前算法(详解)

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

WBOY
WBOYOriginal
2016-06-13 11:49:12903browse

复制代码 代码如下:


  /******************************************************
     * 逐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