I came across a part of code which extracts third bit of
bool flag = (variable & 0x4) == 0x4;
However, the same can be achieved by
bool flag = variable & 4;. Isn’t it? Any reason that this bit extraction specification need to have additional check with
== 0x4 ?
It’s the same as far as the compiler is concerned. I didn’t even turn on optimizations and got the same assembly:
Thea above with with gcc. There’s some subtle differences with msvc, but it’s the same number of instructions.