PHP | gmp_scan0()函数

gmp_scan0()是一个内置函数,用于扫描gmp编号中的“0”( GNU多重精度:适用于大数字 )从给定的索引开始,向数字中的最高有效位移动。

null

语法:

gmp_scan0($num, $index)

参数: 此函数接受两个参数,如下所述:

  • $num :此参数是GMP编号,必须通过。该参数可以是PHP 5.6版及更高版本中的GMP对象,也可以传递数字字符串,前提是可以将该字符串转换为数字。
  • 美元指数 :此参数表示要开始搜索的数字$num的位表示中的索引或位置。

返回值: 函数返回我们在数字中找到“0”的位置。

例如:

Input : gmp_scan0("101111101", 6)
Output : 7

Input : gmp_scan0("111001111", 2)
Output : 4

下面的程序演示了PHP中的gmp_scan0()函数:

项目1: 当作为GMP编号的数字字符串作为参数传递时,程序将查找GMP编号中“0”位的位置。

<?php
// PHP program to find position of "0" bit in GMP
// number passed as arguments
// strings as GMP numbers
$num = "10110001" ;
$pos = 2;
echo gmp_scan0( $num , $pos ) . "" ;
?>


输出:

6

方案2 :当GMP编号作为参数传递时,用于查找GMP编号中“0”位位置的程序。

<?php
// PHP program to find position of "0" bit in GMP
// number
//creating GMP numbers using gmp_init()
$num = gmp_init(10001111101);
$pos = 2;
echo gmp_scan0( $num , $pos ) . "" ;
?>


输出:

7

参考: http://php.net/manual/en/function.gmp-scan0.php

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享