php 不同的最右边的位

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 不同的最右边的位相关的知识,希望对你有一定的参考价值。

// DDD:
function differentRightmostBit($n, $m) {
  return call_user_func(function($n,$m){
    $na = str_split(strrev(str_pad(decbin($n),32,'0',STR_PAD_LEFT)));
    $ma = str_split(strrev(str_pad(decbin($m),32,'0',STR_PAD_LEFT)));
    for($i = 0; $i <32; $i++){
      if($na[$i] != $ma[$i]){
        return pow(2,$i);
      }
    }
  }, $n,$m); ;
}

function differentRightmostBit($n, $m) {
  return pow(2, strspn(strrev(sprintf('%032b', $n)) ^ strrev(sprintf('%032b', $m)), "\0")) ;
}

function differentRightmostBit($n, $m) {
  return (($n ^$m) &-($n ^$m));
}

以上是关于php 不同的最右边的位的主要内容,如果未能解决你的问题,请参考以下文章