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.
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.
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.
Program 2: Program to calculate the population count of a number when GMP numbers are passed as arguments.
- How to get the function name inside a function in PHP ?
- p5.js | pan() Function
- p5.js | str() function
- p5.js | hue() function
- PHP | Ds\Map xor() Function
- p5.js | hex() function
- CSS | url() Function
- PHP | Ds\Map put() Function
- PHP | min( ) Function
- PHP | Ds\Map last() Function
- PHP | Ds\Map map() Function
- PHP | each() Function
- p5.js | max() function
- D3.js | d3.min() function
- PHP | ord() Function
- p5.js | value() Function
- p5.js | min() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.