** PITON: LITTLE SIGNIFICANT BIT METHOD **
>>> def is_odd(i): return bool(i & 1) >>> def is_even(i): return not is_odd(i) >>> [(j, is_odd(j)) for j in range(10)] [(0, False), (1, True), (2, False), (3, True), (4, False), (5, True), (6, False), (7, True), (8, False), (9, True)] >>> [(j, is_even(j)) for j in range(10)] [(0, True), (1, False), (2, True), (3, False), (4, True), (5, False), (6, True), (7, False), (8, True), (9, False)] >>>
See if this can help you or not.
Explanation:
Check if the integer is even or odd. There are several ways to solve this problem: use even and odd predicates if the language provides them. Check the smallest significant digit. With binary integers, I'm bitwise and 1 is 0 iff I'm even or 1 if f is odd. Divide me by 2. The remainder is 0 if I'm even. The remainder is +1 or -1 if f is odd. Use modular congruences: I ≡ 0 (mod 2) if I'm even. i ≡ 1 (mod 2) if i am odd.