小编典典

检查是否设置了位

c#

如何检查某个字节中的某个位是否已设置?

bool IsBitSet(Byte b,byte nPos)
{
   return .....;
}

阅读 477

收藏
2020-05-19

共1个答案

小编典典

听起来有点像作业,但是:

bool IsBitSet(byte b, int pos)
{
   return (b & (1 << pos)) != 0;
}

pos 0是最低有效位,pos 7是最高有效位。

2020-05-19