使我感到沮丧的代码如下:
bool a = 0x00000FF0 & 0x00000FF0 == 0x00000FF0;
if (a) {
Serial.println("True");
} else {
Serial.println("False");
}
这将打印“ False”。我真的不明白为什么。更多测试:
bool a = 0x00000FF0 & 0x00000FF0 == 0x00000FF0;
Serial.println(a);
版画0
。
和:
unsigned long a = 0x00000FF0 & 0x00000FF0;
Serial.println(a, HEX);
版画FF0
。
运算符优先级,带有警告:
warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
改成
bool a = (0x00000FF0 & 0x00000FF0) == 0x00000FF0;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句