<?php
bool gmp_testbit ( GMP|int|string $num, int $index )
where,
$num = The value to test
$index = The index of the bit to test
?>
<?php
// Run this code several times
$a01 = mt_rand( -10000, 1000000);
// Try other values for this mt_rand
$i01 = mt_rand(-2, 2);
// Also try other values for this mt_rand
// Special attention to negative values
$b01 = gmp_testbit($a01, $i01);
if($b01 == true)
{
echo 'The bit ( ' . $a01 . ', ' . $i01 . ' ) is set<br><br>';
}
else
{
echo 'The bit ( ' . $a01 . ', ' . $i01 . ' ) is NOT set<br><br>';
}
?>
<?php
echo PHP_VERSION . '<br><br>';
$a02 = 100000;
$i02 = -1;
// Attention to this value
$b02 = gmp_testbit($a02, $i02);
if($b02 == true)
{
echo 'The bit ( ' . $a02 . ', ' . $i02 . ' ) is set<br><br>';
}
else
{
echo 'The bit ( ' . $a02 . ', ' . $i02 . ' ) is NOT set<br><br>';
}
?>