Monday, April 29, 2013

How to Check Bit is Set (Compare to Bits)

I had a recent requirement to check whether bit is set looking another bit. But then i found; it is easy to compare integer values it self rather than converting to bit arrays.

public bool isBitSet(int value , int checkBit) 
return (value & checkBit) == checkBit;

Ex: I want to check number 8 is set in 6164 ,

You can get it by isBitSet(6164,8)

Post a Comment