gmp_testbit()是PHP中的一个内置函数,用于检查给定gmp编号的指定位是否正确( 多精度 :对于大数字)是否已设置。
null
语法:
gmp_testbit($num, $index)
参数: 该函数接受两个强制性参数,如下所述:
- $num– 此函数接受一个GMP编号 $num 要检查其指定的位。该参数可以是PHP 5.6版及更高版本中的GMP对象,也可以传递数字字符串,前提是可以将该字符串转换为数字。
- 美元指数- 要检查其$num位的指定索引。它是一个整数。
返回值: 函数返回 符合事实的 如果指定 美元指数 位已设置,否则返回 错误的 如果未设置位。
例如:
Input : $num=4 $index=2 Output : true Input : $num=9 $index=2 Output : false
下面的程序说明了gmp_testbit()函数的用法:
项目1: 下面的程序演示了当gmp number作为参数传递时,gmp_testbit()函数的工作原理。
<?php // PHP program to check the sign // of a number // numeric string arguments $num = gmp_init( "1001" , 2); $index1 = 2; $index2 = 0; // checks if the 2nd index bit in 9 (1001) is set or not var_dump(gmp_testbit( $num , $index1 )). "" ; // checks if the 0th index bit in 9 (1001) is set or not var_dump(gmp_testbit( $num , $index2 )); ?> |
输出:
bool(false) bool(true)
项目2: 下面的程序演示了当数字字符串作为参数传递时,gmp_testbit()的工作原理。
<?php // PHP program to check the sign // of a number // numeric string arguments $num = "9" ; $index1 = 2; $index2 = 3; // checks if the 2nd index bit in 9 (1001) // is set or not var_dump(gmp_testbit( $num , $index1 )). "" ; // checks if the 3rd index bit in 9 (1001) // is set or not var_dump(gmp_testbit( $num , $index2 )); ?> |
输出:
bool(false) bool(true)
参考: http://php.net/manual/en/function.gmp-testbit.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END