The condition (left side of the ?) is different.
(a % 2 == 0)
is true when a is an even number.
a % 2
is 1 (which is treated as true) when a is an odd number.
modulo and boolean logic for a bit operation is clunky ... a&1 is true for odd, a^1 is true for even gets rid of the excess == and provides a consistent look and feel. This should work on signed values, though not all bit stuff will.
Last edited on
you are right. And I don't see a 1 op way to test even, everything needs at least 2 operations. There should be one ... I feel like I missed something dumb, that you can't say 'is this bit 0' in one touch...
I think some chips have a way to test a single bit but in general, I don't know of anything you can do in asm here that you can't do with logic ops for a typical processor.
I agree that test odd and branch to even is the most efficient way. Which is what I have done for so long that I had forgotten about the even test weirdness.
Last edited on