取出一个字节(byte)中的每一位(bit)

转载连接:


https://blog.csdn.net/qq_21794823/article/details/53517628



  1. 例:
  2. byte byData = 0x36;
  3. int n0, n1, n2, n3, n4, n5, n6, n7;
  4. n0 = (byData & 0x01) == 0x01 ? 1 : 0;
  5. n1 = (byData & 0x02) == 0x02 ? 1 : 0;
  6. n2 = (byData & 0x04) == 0x04 ? 1 : 0;
  7. n3 = (byData & 0x08) == 0x08 ? 1 : 0;
  8. n4 = (byData & 0x10) == 0x10 ? 1 : 0;
  9. n5 = (byData & 0x20) == 0x20 ? 1 : 0;
  10. n6 = (byData & 0x40) == 0x40 ? 1 : 0;
  11. n7 = (byData & 0x80) == 0x80 ? 1 : 0;

你可能感兴趣的:(c#)