什么是正确的方法来检查是否在php中打开了位字段 [英] What is the correct way to check if bit field is turn on in php
本文介绍了什么是正确的方法来检查是否在php中打开了位字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检查位字段是否打开的正确方法是什么-(在php中)?
What is the correct way to check if bit field is turn on - (in php) ?
我想检查来自db(mysql)的位字段是否打开.
I want to check a bit field that come from db(mysql) if is turn on or not.
这是正确的方法吗?
if($bit & 1)
还有其他方法吗?
我看到有人代码使用 ord()功能,对吗?
I see somebody code that using ord() function , it is correct ?
像if(ord($bit) == 1)
推荐答案
使用
if( $bit & (1 << $n) ) {
// do something
}
其中$n
是第 n 位,以得到减1 (例如,$n=0
是获得最低有效位)
Where $n
is the n-th bit to get minus one (for instance, $n=0
to get the least significant bit)
这篇关于什么是正确的方法来检查是否在php中打开了位字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文