)
{
echo 'true\r\n';
}
else
{
//should get here
echo 'false\r\n';
}
?
- Theo
-Original Message-
From: Miguel Cruz [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 07, 2002 5:04 PM
To: Charlie Killian
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Test for one bit set
On Sun, 7 Apr 2002, Charlie Killian wrote:
How can I test if a number only has on bit set?
So testing different numbers will return TRUE or FALSE:
testing 0001 would return TRUE.
testing 0011 would return FALSE.
Think back to math class when you were 14!
function
This shows all integers from 1 to 10 that have the 2 least significant
bits set:
?php
for ($i = 1; $i = 10; $i++)
{
if ($i 3)
{
echo($i . \n);
}
}
?
bvr.
Charlie Killian wrote:
How can I test if a number only has on bit set?
So testing different
On Sun, 2002-04-07 at 13:38, Charlie Killian wrote:
How can I test if a number only has on bit set?
So testing different numbers will return TRUE or FALSE:
testing 0001 would return TRUE.
testing 0011 would return FALSE.
TIA
Charlie
AND them bitwise:
?php
Thanks to all those that replied. Especially Torben. (What have you been up
to?)
Miguel's solution works great.
Check out the example below:
?php
function isOneBitSet($n)
{
$x = log($n)/log(2);
return ($x == intval($x));
}
for ($i = 0; $i 32769; ++$i) {
if(isOneBitSet($i)) {
5 matches
Mail list logo