Reputation: 51
strcat(b, ((x & z) == z) ? "1" : "0");
I understand strcat()
function and the conditional (ternary) operator. But I don't know what (x & z) == z
means.
Upvotes: 1
Views: 788
Reputation: 2580
(x & z) == z means in 'x', ALL the bits which are SET in 'z' is SET.
'x' must contain all the bits set OR additionally some more bits may also be set. Then this condition becomes true.
Upvotes: 1
Reputation: 2547
The means:
Concatenate "1"
to string b
if bitwise And of x
and z
is same as z
,else concatenate "0"
to string b
.
x&z
means bitwise anding of x
and z
.
The result is then compared with z
.
If the result is same as z
then condition evaluates to be TRUE otherwise FALSE.
Upvotes: 2
Reputation: 134286
&
is the bitwise AND operator.
here, (x & z) == z
means, perform a bitwise AND of x
and z
and if that value equals to z
, then....
Ref: Chapter 6.5.10, C11
standard, "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).
Upvotes: 4