以下语句中的单个 & 是什么意思?

What does the single & in the following statement mean?

strcat(b, ((x & z) == z) ? "1" : "0");

我了解 strcat() 函数和条件(三元)运算符。但是我不知道(x & z) == z是什么意思

& 是按位与运算符。

这里,(x & z) == z 的意思是,对 xz 进行按位与运算,如果该值等于 z,那么....

参考:第 6.5.10 章,C11 标准,"Bitwise AND operator"

The result of the binary & operator is the bitwise AND of the operands (that is, each bit in the result is set if and only if each of the corresponding bits in the converted operands is set).

意思是:

如果按位 xzz 相同,则将 "1" 连接到字符串 b,否则将 "0" 连接到字符串 b.

x&z 表示 xz.

的按位与运算

然后将结果与 z 进行比较。

如果结果与 z 相同,则条件评估为 TRUE,否则为 FALSE。

(x & z) == z 表示在 'x' 中,所有在 'z' 中设置的位都已设置。

'x' 必须包含所有设置的位,或者还可以设置更多的位。那么这个条件成立。