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

发布于:2021-10-25 12:11:43

转载连接:

??


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













    例:













    byte byData =
    0x36;














    int n0, n1, n2, n3, n4, n5, n6, n7;







    n0 = (byData &
    0x01) ==
    0x01 ?
    1 :
    0;







    n1 = (byData &
    0x02) ==
    0x02 ?
    1 :
    0;







    n2 = (byData &
    0x04) ==
    0x04 ?
    1 :
    0;







    n3 = (byData &
    0x08) ==
    0x08 ?
    1 :
    0;







    n4 = (byData &
    0x10) ==
    0x10 ?
    1 :
    0;







    n5 = (byData &
    0x20) ==
    0x20 ?
    1 :
    0;







    n6 = (byData &
    0x40) ==
    0x40 ?
    1 :
    0;







    n7 = (byData &
    0x80) ==
    0x80 ?
    1 :
    0;

相关推荐

最新更新

猜你喜欢