@jonnin
No, even for positive unsigned integers like 4, that doesn't work. Simply (!(x & 1)) is closer. Additionally, for negative values in (e.g., two's one's complement representation) this doesn't work for all x < 0.
Write an expression that evaluates to true if the integer variable x contains an even value, and false if it contains an odd value .
One interpretation of this could be that 769 would evaluate to true since it contains 6 (an even value) and the same number would also evalute to false since it contains 7 and 9 and hence the problem is ill-defined???
Or, more specifically, what does 'containing a value' mean for an integer type?
I was way off (trying to think when tired, and failed) ... but it does work on signed values if you do it right.
the trick is to look at the least bit, which if 1, is odd.
try 4, for example, that is binary 100 and that works.
now try -4... the 2's comp is flip bits and +1:
more precisely, 4 in a byte is 00000100
and -4 in a byte is then 11111100 ... still works (flip all bits, add 1)
because its the least bit, and that is always 0 for an even value, and you flip it, so its always 1, then add 1, its always 0 again, ... so it will work on negatives just fine.