Re: Anyway of knowing whether a integer is odd or even
| From: | J Smith | Date: | Tue, 09 Oct 2001 20:18:09 +0000 |
| Subject: | Re: Anyway of knowing whether a integer is odd or even | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-70533@lists.php.net to get a copy of this message | ||
Is
if ($theInt & 1)
really that much harder to read than
if ($theInt % 2 > 0)
?
And why wouldn't you want to get the most performance out of your code,
regardless of the language, scripting or otherwise? Especially when it's a
one or two character switch that makes the difference?
I doubt that PHP should be classified as a scripting language any more
than Perl is. Scripting languages are usually used to glue different
applications together, like a shell script that uses awk and sed or
whatever. PHP can be used to build applications, so it's more than a
scripting language. Interpreted language is more like it.
J
David Otton wrote:
> On Tue, 09 Oct 2001 13:07:17 -0400, you wrote:
>
>>It is generally faster
>
> (but harder to read)
>
>>to use bitwise operators...
>>
>>if ($theInt & 1)
>> print "$theInt is odd";
>>else
>> print "$theInt is even";
>>
>>This is usually the case for most languages, like C or C++ or what have
>>you. It's probably the same in PHP, since the & operator doesn't need to
>>worry about returning the remainder, just the bits that are set in both
>>$theInt and 1.
>
> I'm sure I don't want to get into this, but...
>
> If speed is that important, why would you use a scripting language?
>
> djo