Re: If value is odd or not
| From: | Adam Zey | Date: | Fri, 02 Jun 2006 15:18:12 +0000 |
| Subject: | Re: If value is odd or not | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237285@lists.php.net to get a copy of this message | ||
IG wrote:
Jochem Maas wrote:But there was something wrong with it. You're using string operations on a number to find out if it is odd. That means that it is many TIMES slower, and if he needs to do this in a loop, using string functions is going to be horribly slow compared to a simple modulus. Just because code "works" doesn't mean that it is acceptable. Spending a thousand times more computational time to solve a problem than is needed is a recipe for disaster. Regards, Adam Zey.Jonas Rosling wrote:ie my answer! I think the % operator is the best way, but there was nothing wrong with the answer I gave in that it would let you know whether the value is odd or not. But, I guess being not as clever as the other guys means I better go... sob sob....Hi all, is there any easy why to check if a value is odd or not?ignore every answer that doesn't use the % operator.Thanks // Jonas