Even or odd: Difference between revisions

PascalABC.NET
(PascalABC.NET)
Line 3,333:
<syntaxhighlight lang="parigp">odd(n)=bitand(n,1);</syntaxhighlight>
PARI can use the same method as [[#C|C]] for testing individual words. For multiprecision integers (t_INT), use <code>mpodd</code>. If the number is known to be nonzero, <code>mod2</code> is (insignificantly) faster.
 
=={{header|PascalABC.NET}}==
 
<syntaxhighlight lang="pascal">
function IsOddRemainder(x: integer) := x mod 2 <> 0;
 
function IsEvenRemainder(x: integer) := x mod 2 = 0;
 
function IsOddBitwise(x: integer) := x and 1 = 1;
 
function IsEvenBitwise(x: integer) := x and 1 = 0;
 
begin
var x := 3;
Println(x.IsEven,x.IsOdd); // Standard Predicates
Println(IsEvenRemainder(x),IsOddRemainder(x));
Println(IsEvenBitwise(x),IsOddBitwise(x));
end.
</syntaxhighlight>
 
=={{header|Pascal}}==
222

edits