And*_*rey 25
http://php.net/manual/en/language.operators.bitwise.php
($x >> 1) & 1
Run Code Online (Sandbox Code Playgroud)
Andrey的不错回答,当然是他的解决方案。这是使用字符串操作的另一种方式(我知道,我知道...):
substr(decbin($x), -2, 1)
Run Code Online (Sandbox Code Playgroud)
这是一个更普遍的函数来提取位范围.
function extract_bits($value, $start_pos, $end_pos)
{
$mask = (1 << ($end_pos - $start_pos)) - 1;
return ($value >> $start_pos) & $mask;
}
Run Code Online (Sandbox Code Playgroud)
例如,从13中提取第二位的值,它将是:
extract_bits(13,1,2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15010 次 |
| 最近记录: |