PHP | gmp_popcount() Function Last Updated : 14 Apr, 2018 Comments Improve Suggest changes Like Article Like Report The gmp_popcount() is a built-in function in PHP which is used to find the population count of a GMP number (GNU Multiple Precision : For large numbers). We can also say that this function is used to find the number of set bits in the binary representation of a GMP number. Syntax: gmp_popcount ( $num ) Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. 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. Return Value: This function returns an integer which is the population count or the number of set bits in binary representation of a GMP number passed to it as parameter. Examples: Input : "9" Output : 2 Input : "25" Output : 3 Below programs illustrate the gmp_popcount() function in PHP : Program 1: Program to calculate the population count of a number when numeric strings as GMP numbers are passed as arguments. php <?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."\n"; // calculates the population count of a number $pcount = gmp_popcount($num2); echo $pcount."\n"; ?> Output: 2 3 Program 2: Program to calculate the population count of a number when GMP numbers are passed as arguments. php <?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."\n"; // calculates the population count of a number $pcount = gmp_popcount($num2); echo $pcount."\n"; ?> Output: 2 3 Reference: http://php.net/manual/en/function.gmp-popcount.php Comment More infoAdvertise with us Next Article PHP | gmp_popcount() Function B barykrg Follow Improve Article Tags : Misc Web Technologies PHP PHP-gmp Practice Tags : Misc Similar Reads 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_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 PHP | gmp_powm() Function The gmp_powm() is an inbuilt function in PHP which is used to calculate the number raised to a power of two GMP numbers modulo of another GMP number.(GNU Multiple Precision: For large numbers)Syntax: gmp_pow( $base, $exp, $mod) Parameters: The function accepts three mandatory parameters $base, $exp 2 min read PHP | gmp_rootrem() Function The gmp_rootrem() is a built-in function in PHP which is used to calculate the nth root of a GMP number (GNU Multiple Precision : For large numbers) and returns the integer component of the nth root and its remainder . Syntax : gmp_rootrem($num,$n) Parameters : This function accepts two mandatory pa 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_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_xor() Function The gmp_xor() is an in-built function in PHP which is used to calculate the XOR of 2 GMP numbers (GNU Multiple Precision : For large numbers). Syntax: gmp_xor( $num1, $num2 ) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters shown in the above syntax. These pa 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_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 Like