PHP | gmp_testbit() Function Last Updated : 14 Apr, 2018 Summarize Suggest changes Share Like Article Like Report The gmp_testbit() is an in-built function in PHP which checks if the specified bit of a given GMP number(GNU Multiple Precision: For large numbers) is set or not. Syntax: gmp_testbit($num, $index) Parameters: The function accepts two parameters which are mandatory and are described below: $num - The This function accepts one GMP number $num whose specified bit is to be checked.This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. $index- The specified index whose bit in $num is to be checked. It is an integer. Return Value: The function returns true if the specified $index bit is set, otherwise it returns false if the bit is not set. Examples: Input : $num=4 $index=2 Output : true Input : $num=9 $index=2 Output : false Below programs illustrate the use of gmp_testbit() function: Program 1: The program below demonstrates the working of gmp_testbit() function when GMP number is passed as an argument. php <?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))."\n"; // checks if the 0th index bit in 9 (1001) is set or not var_dump(gmp_testbit($num, $index2)); ?> Output: bool(false) bool(true) Program 2: The program below demonstrates the working of gmp_testbit() when numeric string is passed as an argument. php <?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))."\n"; // checks if the 3rd index bit in 9 (1001) // is set or not var_dump(gmp_testbit($num, $index2)); ?> Output: bool(false) bool(true) Reference: http://php.net/manual/en/function.gmp-testbit.php Advertise with us Next Article PHP | gmp_strval() Function C ChetnaAgarwal Follow Similar Reads PHP | gmp_setbit() Function The gmp_setbit() function is an inbuilt function in PHP which is used to set the bit index in given $num. Syntax: void gmp_setbit( GMP $num, int $index, bool $bit_on ) Parameters: This function accepts three parameters as mentioned above and described below: $num: It is a required parameter. This pa 2 min read PHP | gmp_sub() Function The gmp_sub() is an in-built function in PHP which returns the subtraction of the two GMP numbers.(GNU Multiple Precision: For large numbers) Syntax: gmp_sub($num1, $num2) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters shown in the above syntax. These param 2 min read PHP | gmp_sign() Function The gmp_sign() is an in-built function in PHP which checks the sign of a given GMP number (GNU Multiple Precision: For large numbers). Syntax: gmp_sign($num) Parameters: This function accepts one GMP number $num as mandatory parameter shown in the above syntax. This parameter can be a GMP object in 2 min read PHP | gmp_sqrt() Function The gmp_sqrt() is a built-in function in PHP which is used to calculate the square root of a GMP number (GNU Multiple Precision : For large numbers). This function returns only the integral part of the square root of the GMP number. Syntax: gmp_sqrt ( $num ) Parameters: This function accepts a GMP n 2 min read PHP | gmp_strval() Function The gmp_strval() is an inbuilt function in PHP which returns the string value of a GMP number. (GNU Multiple Precision: For large numbers). Syntax: string gmp_strval ( GMP $num, int $base ) Parameters: The function accepts two parameters $num and $base as shown above and described below. $num - The 3 min read PHP | gmp_root() Function The gmp_root() is an in-built function in PHP which returns the integer part of the N-th root of a GMP number(GNU Multiple Precision: For large numbers).Syntax:  gmp_root( $num, $n ) Parameters: The function accepts two mandatory parameters $num and $n.  $num - This is the GMP number whose integer 2 min read Article Tags : Misc Web Technologies PHP PHP-gmp Practice Tags : Misc Like