Re: Computer programmers' habits in electronics



On Thu, 22 Dec 2005 04:44:00 GMT, the renowned "Mike Young"
<boat042-spam@xxxxxxxxx> wrote:

>"Spehro Pefhany" <speffSNIP@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>news:0u2kq1h7cm70jgjmj5hari4kug5308ihtn@xxxxxxxxxx
>>> std::reverse(pStr, pStr + (len ? len : strlen(pStr)));
>>>}
>>
>> Isn't that kinda cheating?
>
>I suppose you should also ding me for <string.h>.
>
>It's a valid answer, and meaningful of itself. The follow up questions would
>bring it back to where we started.
>
>If you're not tired of the game yet, write:
>
>// return true if val is an integer power of 2; false otherwise.
>bool IsPowerOf2(unsigned val);

bool IsPowerOf2(unsigned val)
{
unsigned i=val, j=1;
while (i >>= 1) j*=2;
return (j == val);
}



Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff@xxxxxxxxxxxx Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
.


Loading