gmp_popcount()是PHP中的一个内置函数,用于查找gmp编号的人口计数( 多精度 :对于大数字)。我们还可以说,这个函数用于在二进制表示的GMP数中查找设置位数。
null
语法:
gmp_popcount ( $num )
参数: 此函数接受GMP编号 $num 作为强制参数,如上述语法所示。该参数可以是PHP 5.6版及更高版本中的GMP对象,也可以传递数字字符串,前提是可以将该字符串转换为数字。
返回值: 此函数返回一个整数,它是作为参数传递给它的GMP数的二进制表示形式的总体计数或设置位数。
例如:
Input : "9" Output : 2 Input : "25" Output : 3
下面的程序演示了PHP中的gmp_popcount()函数:
项目1: 当数字字符串作为参数传递时,用于计算数字的填充计数的程序。
<?php // PHP program to calculate population count // of a GMP number passed as arguments // strings as GMP numbers $num1 = "9" ; $num2 = "25" ; // calculates the population count of a number $pcount = gmp_popcount( $num1 ); echo $pcount . "" ; // calculates the population count of a number $pcount = gmp_popcount( $num2 ); echo $pcount . "" ; ?> |
输出:
2 3
项目2: 当GMP数字作为参数传递时,用于计算数字的总体计数的程序。
<?php // PHP program to calculate population count // of a GMP number passed as arguments // creating GMP numbers using gmp_init() $num1 = gmp_init(9, 10); $num2 = gmp_init(25, 10); // calculates the population count of a number $pcount = gmp_popcount( $num1 ); echo $pcount . "" ; // calculates the population count of a number $pcount = gmp_popcount( $num2 ); echo $pcount . "" ; ?> |
输出:
2 3
参考: http://php.net/manual/en/function.gmp-popcount.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END