I tried to convert it to binary
That might have got in the way of understanding. The exact bit-patterns of 0x65
and 0x55
are completely irrelevant to the required result, all that matters is that they're both non-zero. You could consider a = (0x65 && 0x55)
to be equivalent to something like:
if (0x65 != 0) goto condition_false;
if (0x55 != 0) goto condition_false;
a = 1;
goto condition_end;
condition_false:
a = 0;
condition_end:
A given implementation might be able to emit code more efficient than that (although I have seen pretty much that code emitted, with each if ... goto
being a test and branch in the assembly). The more-efficient code might involve some bit operations to avoid branches. For that matter, in this example involving constants the compiler would probably just emit a = 1;
.
The meaning of the &&
operator is in terms of conditional execution, though. For example if you write f() && g()
then it is guaranteed that when f
returns a false value, g
is not called. If it's possible to get the same result by bit-twiddling then that's likely a bonus for performance.