取字节具体位的值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JeanShaw/article/details/52421239

有的时候,我们需要接收字节中某一位的值来对一些硬件设备进行控制,下面是非常适用的一个方法。
private static int GetBit(byte b, int index) { return ((b & (1 << index)) > 0) ? 1 : 0; }

猜你喜欢

转载自blog.csdn.net/JeanShaw/article/details/52421239