The gmp_hamdist() is a built-in function in PHP which is used to find the hamming distance between two GMP numbers (GNU Multiple Precision : For large numbers).
Hamming distance between two numbers is defined as number of mis-matching bits in their binary representation.
gmp_hamdist ( $num1, $num2)
Parameters: This function accepts two GMP numbers $num1 and $num2 as shown in the above syntax. Both of these parameters are mandatory to be passed and must be positive. This function finds the hamming distance between the two numbers $num1 and $num2. These parameters 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 a GMP number which is the calculated hamming distance of the two numbers passed to it as arguments.
Input: $a = "3", $b = "11" Output: 1 Explanation: Binary representation of 3 is 0011 Binary representation of 11 is 1011. So, they differ by only 1 bit. Input: $a = "4", $b = "4" Output: 0
Below programs illustrate the gmp_hamdist() function in PHP :
Program 1: Program to calculate the hamming distance when numeric strings as GMP numbers are passed as arguments.
Program 2: Program to calculate the hamming distance when GMP numbers are passed as arguments.
- How to get the function name inside a function in PHP ?
- PHP | dir() Function
- PHP | Ds\Set contains() Function
- CSS | url() Function
- PHP | exp() Function
- D3.js | d3.set.has() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Map first() Function
- p5.js | arc() Function
- p5.js | mag() Function
- PHP | Ds\Set first() Function
- CSS | var() Function
- PHP | pos() Function
- PHP | key() Function
- D3.js | d3.hsl() Function
- PHP | Ds\Map get() Function
- PHP | end() 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.