Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道为什么二进制数不能与按位运算符一起使用?
//works msgSize = (*(msgbody+1) & 0x80)?*(msgbody+5):*(msgbody+3); //doesn't compile msgSize = (*(msgbody+1) & 0b10000000)?*(msgbody+5):*(msgbody+3);
C 不支持二进制文字;如果它们可用,它们就是扩展。我建议您的编译器发出错误,因为它无法识别二进制文字0b10000000。因此,您的编译器可能也会对此发出错误:
0b10000000
int main(void) { int msgSize = 0b10000000; return 0; }
我建议使用0x80or1 << 7代替。
0x80
1 << 7