gmp_scan0


gmp apg

SCAN for 0 in a GMP number.





This function scans $num1, starting with bit $start, towards more significant bits, until the first clear bit is found.



<?php

int gmp_scan0 
GMP|int|string $num1int $start )


where,

$num1 The GMP number to scan

$start 
The starting bit

?>
 

$num1


The first GMP number to scan.



$start


The starting bit.



  1 EXERCISE   

<?php

$str01 
2;
// Try other starting bit

$num01 "11111111";
// Try other number

$s01 gmp_init($num01$str01);

var_dump($s01);

echo 
'<br><br>';

for(
$b01 0$b01 <= 64$b01++)
{

$sc01 gmp_scan0($s01$b01);
$tb01 gmp_testbit($s01$b01);

echo 
"<br>gmp_scan0($s01$b01) = " gmp_scan0($s01$b01) . '<br>';
var_dump($tb01);
echo 
'<br>';

}

?> 

  2 EXERCISE   

<?php

echo "gmp_scan0(\"34234\", 1) = " 
                 
gmp_scan0("434234"1) ."<br><br>";

echo 
"gmp_scan0(4096, 0) = " 
                 
gmp_scan0(40960) ."<br><br>";

echo 
"gmp_scan0(\"1000000000\", 5) = " 
                 
gmp_scan0("1000000000"5) ."<br><br>";

echo 
"gmp_scan0('1000000000', 200) = " 
                 
gmp_scan0("1000000000"200) ."<br><br>";

try {
    
var_dump(gmp_scan0("434234", -10));
} catch (
\ValueError $e) {
    echo 
$e->getMessage() . "<br><br>";
}

$n gmp_init("24234527465274");
var_dump(gmp_scan0($n10));

try {
    
var_dump(gmp_scan0(array(), 200));
} catch (
\TypeError $e) {
    echo 
$e->getMessage() . "<br><br>";
}

?>