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 00010000 would return TRUE. > testing 00000011 would return FALSE. > > TIA > > Charlie
AND them bitwise: <?php error_reporting(E_ALL); $bit = 16; $foo = bindec('00010000'); $bar = bindec('00000011'); echo "$foo; $bar\n"; if ($foo & $bit) { echo "Bit 5 is set.\n"; } else { echo "Bit 5 is not set.\n"; } if ($bar & $bit) { echo "Bit 5 is set.\n"; } else { echo "Bit 5 is not set.\n"; } ?> Torben -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php