繁体   English   中英

如何使用C中的按位运算符判断数字是否等于另一个数字

[英]How to tell if a number equals another number using bitwise operators in C

我正在编写一个程序,我有一个无限循环做一些停止条件,如果一些变量a == 1只使用按位运算符。

我该怎么做?

示例代码:

while(1){
    int a;
    //do some work
    if (a==1){ // how do I say this with bitwise operators and no "!"
        break;
    }
}

由于OP的停止条件是在循环结束时,代码可以使用do()循环。

int a;
do {
  // some work that sets `a`
} while (a^1);

a的值为1时, a ^ 1 - > 0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM