PHP | gmp_setbit() Function Last Updated : 31 Oct, 2023 Comments Improve Suggest changes Like Article Like Report 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 parameter gives the value to be modified. This parameter can be a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 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: It is a required parameter. This parameter provides the index to be set. Here index 0 represents the least significant bit.$set_state: This parameter sets the bits, if "True" it sets the bit to 1/on and if "False", it will clear the bit that is set the bit to 0/off.Return Value: This function returns the GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later. Program 1: Program to illustrate gmp_setbit() function having index 0: php <?php // PHP program to demonstrate the gmp_setbit() function // with index 0 // It will create a gmp number $num = gmp_init("2"); // gmp_strval will return the string value of a GMP number // when the argument is numeric string and // the second parameter is present echo gmp_strval($num), ' -> 0b', gmp_strval($num, 2), "\n"; gmp_setbit($num, 0); // 0b10 now becomes 0b11 echo gmp_strval($num), ' -> 0b', gmp_strval($num, 2); ?> Output: 2 -> 0b103 -> 0b11Program 2: Program of gmp_setbit() function for clearing the bit: php <?php // php program to illustrate gmp_setbit() function // for clearing bit // gmp_init() will create a gmp number $num = gmp_init("3"); // gmp_strval will return the string value of a GMP number // when the argument is numeric string and // the second parameter is present echo gmp_strval($num), ' -> 0b', gmp_strval($num, 2), "\n"; gmp_setbit($num, 0, false); // clearing bit at index 0 echo gmp_strval($num), ' -> 0b', gmp_strval($num, 2); ?> Output : 3 -> 0b112 -> 0b10Reference: http://php.net/manual/en/function.gmp-setbit.php Comment More infoAdvertise with us Next Article PHP | gmp_setbit() Function P priya_1998 Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-gmp Similar Reads PHP | gmp_testbit() Function 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 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 PHP | gmp_sqrtrem() Function The gmp_sqrtrem() 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) with remainder. This function also returns only the integral part in the square root of the GMP number as the gmp_sqrt() function. The remainder is 2 min read PHP | gmp_scan1() Function The gmp_scan1() is an inbuilt function which is used to scan "1" in the GMP number(GNU Multiple Precision : For large numbers) starting from given index which move towards most significant bits in the number. Syntax: gmp_scan1($num, $index) Parameters: This function accepts two parameters as explain 2 min read PHP | gmp_scan0() Function The gmp_scan0() is an inbuilt function which is used to scan "0" in a GMP number(GNU Multiple Precision : For large numbers) starting from given index which move towards most significant bits in the number. Syntax: gmp_scan0($num, $index) Parameters: This function accepts two parameters as explained 2 min read PHP | gmp_pow() Function The gmp_pow() is an inbuilt function in PHP which is used to calculate the power raised to a number of a GMP number and an integer (GNU Multiple Precision: For large numbers). Syntax: gmp_pow( $base, $exp ) Parameters: The function accepts two mandatory parameters $base and $exp. $base - It is the b 2 min read Like