Even or odd: Difference between revisions
Content deleted Content added
alphabetize - step 1 |
alphabetize - step 2 |
||
Line 982:
The result is 1 when i is odd, and 0 when i is even.
=={{header|Prolog}}==
Prolog does not provide special even or odd predicates as one can simply write "0 is N mod 2"
to test whether the integer N is even. To illustrate, here is a predicate that can
be used both to test whether an integer is even and to generate the non-negative even numbers:
<lang prolog>
even(N) :-
(between(0, inf, N); integer(N) ),
0 is N mod 2.
</lang>
===Least Significant Bit===
If N is a positive integer, then lsb(N) is the offset of its least significant bit, so we could write:
<lang prolog>
odd(N) :- N = 0 -> false; 0 is lsb(abs(N)).
</lang>
=={{header|PureBasic}}==
<lang PureBasic>;use last bit method
|