(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
gmp_hamdist — Hamming distance
Returns the hamming distance between num1
and
num2
. Both operands should be non-negative.
num1
GMP 对象、int 或 string,可以按照跟在 gmp_init() 中使用字符串并自动检测 base(即当 base 等于 0 时)相同的逻辑将其解释为数字。
It should be positive.
num2
GMP 对象、int 或 string,可以按照跟在 gmp_init() 中使用字符串并自动检测 base(即当 base 等于 0 时)相同的逻辑将其解释为数字。
It should be positive.
The hamming distance between num1
and num2
, as an int.
示例 #1 gmp_hamdist() example
<?php
$ham1 = gmp_init("1001010011", 2);
$ham2 = gmp_init("1011111100", 2);
echo gmp_hamdist($ham1, $ham2) . "\n";
/* hamdist is equivalent to: */
echo gmp_popcount(gmp_xor($ham1, $ham2)) . "\n";
?>
以上示例会输出:
6 6