On Aug 3, David Dorward said:

>On 3 Aug 2004, at 13:26, [EMAIL PROTECTED] wrote:
>> Does anyone know a simple way to determine if a number is odd or even?
>
>Use the modulus operator. If $foo % 2 has remainder 1, then it is odd,
>if it has remainder 0, then it is even.

While I find this a silly question, I'll chime in with the "computer
scientist"'s response.

Using the bitwise & operator is faster than the modulus operator.

  my $odd = ($num & 1);

-- 
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to