note 29709 added to ref.math
| From: | jl85 at yahoo dot com | Date: | Sat, 22 Feb 2003 14:04:18 +0000 |
| Subject: | note 29709 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44344@lists.php.net to get a copy of this message | ||
Theres another faster way of doing even/odd number checking by using bitwise operators. Don't
ask me how it works, I just found this out by experimenting with it (could the editor possibly
explain?)
if ((1&$num)) {
echo "$num is odd";
}
if (!(1&$num)) {
echo "$num is even";
}
How it works is (1&$num) returns a 1 for odd numbers and returns 0 when it's an even
number.
--
http://www.php.net/manual/en/ref.math.php
http://master.php.net/manage/user-notes.php?action=edit+29709
http://master.php.net/manage/user-notes.php?action=delete+29709
http://master.php.net/manage/user-notes.php?action=reject+29709