Follow

x%2 is 0 for even numbers, but 1 only for POSITIVE odd numbers; it's -1 for negative ones

x&1 is 0 for even numbers, 1 for odd numbers

Also, "parity" appears (in CS, not math) to refer to oddness or evenness of the number of "on" bits, not the number itself.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.