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.