gmp_hamdist
is a function in PHP that calculates the hamming distance between two numbers.
The hamming distance is the number of bit positions in which the two bits are not the same.
gmp_hamdist(GMP|int|string $num1, GMP|int|string $num2): int
The function takes in two parameters:
num1
num2
Both the parameters should be positive.
num1
andnum2
can be a numeric string,object, or of the GMP GNU Multiple Precision Arithmetic Library int
type.
The function returns the hamming distance between num1
and num2
. The value returned is of the int
type.
<?php// gmp_init is used to create a GMP number$val1 = gmp_init("1001010011", 2);$val2 = gmp_init("1011111100", 2);$distance = gmp_hamdist($val1, $val2);echo $distance."\n";?>
6