array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.gmp-hamdist.php', 1 => 'gmp_hamdist', ), 'up' => array ( 0 => 'ref.gmp.php', 1 => 'GMP 関数', ), 'prev' => array ( 0 => 'function.gmp-gcdext.php', 1 => 'gmp_gcdext', ), 'next' => array ( 0 => 'function.gmp-import.php', 1 => 'gmp_import', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/gmp/functions/gmp-hamdist.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
gmp_hamdist — ハミング距離
num1
と num2
の間のハミング距離を返します。オペランドは共に非負とする必要があります。
num1
と num2
のハミング距離を int として返します。
例1 gmp_hamdist() の例
<?php
$ham1 = gmp_init("1001010011", 2);
$ham2 = gmp_init("1011111100", 2);
echo gmp_hamdist($ham1, $ham2) . "\n";
/* ハミング距離は、以下と等しくなります */
echo gmp_popcount(gmp_xor($ham1, $ham2)) . "\n";
?>
上の例の出力は以下となります。
6 6