Re: odd and even numbers
| From: | Brian V Bonini | Date: | Fri, 16 Jan 2004 21:25:50 +0000 |
| Subject: | Re: odd and even numbers | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-174881@lists.php.net to get a copy of this message | ||
On Fri, 2004-01-16 at 15:17, Jake McHenry wrote:
> I have a random number being generated from 1 to 501, is there an easy way for me to tell if
> the result is an odd or even number?
(1 & number) ? odd : even;
E.g.
<?php
$i=1;
echo '<pre>';
while($i < 10) {
(1 & $i) ? print($i . ' is odd') : print($i . ' is even');
echo "\n";
$i++;
}
echo '</pre>';
?>
--
Brian GnuPG -> KeyID: 0x04A4F0DC | URL: www.gfx-design.com/keys
Key Server: pgp.mit.edu
======================================================================
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
GnuPG: http://gnupg.org
http://www.biglumber.com/x/web?qs=0x2C35011004A4F0DC
Linux Registered User #339825 at http://counter.li.org
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc