Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_hamdist

Description

The gmp_hamdist of GMP for PHP hamming distance.

Syntax

gmp_hamdist(
    GMP|int|string $num1,
    GMP|int|string $num2
): int

Parameters

num1

A GMP object, an int or a numeric string.

It should be positive.

num2

A GMP object, an int or a numeric string.

It should be positive.

Return

Returns the hamming distance between num1 and num2, as an int.

Total count of exclusive 1's in binary.

Examples

1 · num1 num2 · GMP

<?

$num1 = 0b1010;
$num2 = 0b1100;

$num1 = gmp_init($num1);
$num2 = gmp_init($num2);

$return = gmp_hamdist($num1, $num2);

echo $return;

?>
2

2 · num1 num2 · int

<?

$num1 = 0b1010;
$num2 = 0b1100;

$return = gmp_hamdist($num1, $num2);

echo $return;

?>
2

3 · num1 num2 · string

<?

$num1 = "0b1010";
$num2 = "0b1100";

$return = gmp_hamdist($num1, $num2);

echo $return;

?>
2

4 · gmp_xor gmp_popcount

<?

$num1 = 0b1010;
$num2 = 0b1100;

$gmp_xor = gmp_xor($num1, $num2);

$gmp_popcount = gmp_popcount($gmp_xor);

echo $gmp_popcount;

?>
2
HomeMenu