这个&符号在C中是什么意思? [英] What does this ampersand mean in C?
本文介绍了这个&符号在C中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在看c代码:
if((VAR_ON&3) > 1)
我不确定 VAR_ON 是什么类型的变量,我猜它是一个指针,但最后的 &3 对它做了什么?如果这是一个重复的问题,我深表歉意,我只是在变量之后找不到任何关于&符号的问题.
I am not sure what kind of variable VAR_ON is, my guess is it is a pointer, but what does the &3 at the end do to it? I apologize if this is a duplicate question, I just could not find any question regarding the ampersand AFTER a variable.
推荐答案
如问题代码中所用,与号&"是按位与"运算.
As used in the question code, the ampersand '&' is a bitwise 'and' operation.
示例(假设 VAR_ON = '21'):
Example (assuming that VAR_ON = '21'):
VAR_ON 21(Decimal) 00010101(Binary)
& 3(Decimal) & 00000011(Binary)
------------ ------------------
1(Decimal) 00000001(Binary)
因此,如果 VAR_ON 为21",则表达式 (VAR_ON&3) 的计算结果为1".'if' 条件为假:
Hence if VAR_ON is '21', the expression (VAR_ON&3) will evaluate to '1'. The 'if' condition would be false:
if((VAR_ON&3) > 1)
这篇关于这个&符号在C中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文