我通常在Java工作,我得到了一些C代码,我没有在任何文档中找到它 - 它可能没有帮助,我不知道它应该做什么所以我不喜欢#39;知道要在文档中查找的位置!
$scope
答案 0 :(得分:4)
Both the mask with 0xff
and the ternary operator are redundant.
The first operation arg0 + arg1 == arg2
is a simple comparison.
C does not have boolean types for the comparison operators, the result is of type int
and its value is either 0
for false or 1
for true.
The ternary operator, almost the same as Java's, is redundant as it evaluates as 0x1
for non 0
and 0x0
for 0
.
The bitwise mask operator &
is also redundant because 0 & 0xff
is 0
and 1 & 0xff
is 1
.
Overall, this expression simplifies to just variable = (arg0 + arg1 == arg2);
which can be written more explicitly as
if (arg0 + arg1 == arg2)
variable = 1;
else
variable = 0;
答案 1 :(得分:2)
arg0 + arg1 == arg2 ? 0x1 : 0x0
表示0x1
arg0 + arg1 == arg2
为true
而0x0
表示arg0 + arg1 == arg2
为false
。
其他所有内容都与Java相同。
?:是一个名为Ternary的快速if / then / else运算符,正如其他人所提到的那样。
答案 2 :(得分:0)
arg0 + arg1
与arg2
进行比较,如果确实输出为0x1
其他0X0
。然后在结果和and
之间进行按位0xff
操作。按位并且与0xff产生相同的值,即
a & 0xff = a;
三元条件
a ? b : c
如果a为真,则结果为b else c。