Home >Backend Development >PHP Tutorial >二进制控最低位固定,其他位依次左移一位,怎么实现?

二进制控最低位固定,其他位依次左移一位,怎么实现?

WBOY
WBOYOriginal
2016-06-23 13:42:04919browse

如 我最低位是1 主要是用来做权限系统判断用的, 每一位代表一个权限,但是最低位固定是用来判断模块的,其他左移的位数都代表一个权限 最后得到的权限码如下都可以了,php代码实现
32位的 前面0都去掉了
 增加:11
修改:101
删除:1001
查询:10001
梳理:100001
纠正:1000001
矫正:10000001




//可以写32个


回复讨论(解决方案)

$i= 3;$temp = $i & 1;echo "\$i = ".decbin($i)." \n<br> ";$i = $i>>1 <<3 | $temp;echo "\$i = ".decbin($i)." \n<br> ";

我想了半天也是这个思路,用得到的每个数都让他或1,再输出就ok了,分全给你了

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