How can I check my byte flag, verifying that a specific bit is at 1 or 0?

前端 未结 10 1168
花落未央
花落未央 2020-12-08 05:11

I use a byte to store some flag like 10101010, and I would like to know how to verify that a specific bit is at 1 or 0.

10条回答
  •  情歌与酒
    2020-12-08 05:31

    Traditionally, to check if the lowest bit is set, this will look something like:

    int MY_FLAG = 0x0001;
    if ((value & MY_FLAG) == MY_FLAG)
        doSomething();
    

提交回复
热议问题