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

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

WBOY
Release: 2016-06-13 11:49:12
Original
937 people have browsed it

复制代码 代码如下:


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

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template