gpt4 book ai didi

c - 如何评估二进制数的真假?

转载 作者:行者123 更新时间:2023-11-30 21:38:13 24 4
gpt4 key购买 nike

如果我写

PORTA =0b00000001;
PORTB =0b00000000;
PORTC =0b11111111;
PORTD =0b10100110;
if(PORTA){
//will this block be true?if yes then why and how it is evaluated
}
if(PORTB){
//smae here,to check true or false.
}
if(PORTC){
//if true then why or false,why?
}
if(PORTD){
//same
}

如果上述说法错误,那么如何检查端口的状态?

最佳答案

通常在 C 中,任何非零数字都将计算为 true。如果要检查端口中特定位的值,请使用二进制 AND 运算符 &。注意:逻辑 AND、&& 和二进制 AND、& 不是同一件事。

在您的问题中,只有 PORTB 会评估为 false。

关于c - 如何评估二进制数的真假?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17260885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com