Absolutely basic Java question which I’m having a hard time finding on Google. What does the following mean:
(7 & 8) == 0?
Is that equivalent to writing:
7 == 0 || 8 == 0?
I wrote a quick main which tests this, and it seems to be the case. I just wanted to make sure I’m not missing anything.
Nope.
&is bitwise and. It sets a bit if the corresponding bits are set in both inputs. Since in binary, 7 is111and 8 is1000, they have no bits in common, so the result is0.There isn’t really any shorthand syntax for the thing you suggest, not on a single line. There are a few workarounds — test for membership in a
SetorBitSet, use aswitchstatement — but nothing that’s both as efficient and as short as just7 == 0 || 8 == 0.