What is the correct way to check if bit field is turn on - (in php) ?
I want to check a bit field that come from db(mysql) if is turn on or not.
is this is the correct way ?
if($bit & 1)
Are there other ways ?
I see somebody code that using ord() function , it is correct ?
like if(ord($bit) == 1)
Use
if( $bit & (1 << $n) ) {
// do something
}
Where $n
is the n-th bit to get minus one (for instance, $n=0
to get the least significant bit)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With