VOOZH about

URL: https://www.geeksforgeeks.org/php/php-gmp_testbit-function/

⇱ PHP | gmp_testbit() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP | gmp_testbit() Function

Last Updated : 11 Jul, 2025
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:
  1. $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.
  2. $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. Output:
bool(false) 
bool(true)
Program 2: The program below demonstrates the working of gmp_testbit() when numeric string is passed as an argument. Output:
bool(false) 
bool(true)
Reference: https://www.php.net/manual/en/function.gmp-testbit.php
Comment
Article Tags: