gmp_testbit


gmp apg

TEST if a bit is set.





This function returns TRUE if the tested bit is set or FALSE otherwise.

If $index < 0 a Warning or a Fatal error is issued.



<?php

bool gmp_testbit 
( GMP|int|string $num, int $index )


where,

$num = The value to test

$index 
= The index of the bit to test

?>
 

$num


The value to test.



$index


The index of the bit to test.



  1 EXERCISE   

<?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>';
}

?> 

  2 EXERCISE   

<?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>';
}

?>