<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Hamming distance</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.gmp-gcdext.html">gmp_gcdext</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.gmp-init.html">gmp_init</a></div> <div class="up"><a href="ref.gmp.html">GMP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.gmp-hamdist" class="refentry"> <div class="refnamediv"> <h1 class="refname">gmp_hamdist</h1> <p class="verinfo">(PHP 4 >= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">gmp_hamdist</span> — <span class="dc-title">Hamming distance</span></p> </div> <div class="refsect1 description" id="refsect1-function.gmp-hamdist-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>gmp_hamdist</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$a</code></span> , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$b</code></span> )</div> <p class="para rdfs-comment"> Returns the hamming distance between <em><code class="parameter">a</code></em> and <em><code class="parameter">b</code></em>. Both operands should be non-negative. </p> </div> <div class="refsect1 parameters" id="refsect1-function.gmp-hamdist-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">a</code></em></span> <dd> <p class="para">It can be either a GMP number <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>, or a numeric string given that it is possible to convert the latter to a number.</p> <p class="para"> It should be positive. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">b</code></em></span> <dd> <p class="para">It can be either a GMP number <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>, or a numeric string given that it is possible to convert the latter to a number.</p> <p class="para"> It should be positive. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.gmp-hamdist-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> A GMP number <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>. </p> </div> <div class="refsect1 examples" id="refsect1-function.gmp-hamdist-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3412"> <p><strong>Example #1 <span class="function"><strong>gmp_hamdist()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$ham1 </span><span style="color: #007700">= </span><span style="color: #0000BB">gmp_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"1001010011"</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ham2 </span><span style="color: #007700">= </span><span style="color: #0000BB">gmp_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"1011111100"</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">gmp_hamdist</span><span style="color: #007700">(</span><span style="color: #0000BB">$ham1</span><span style="color: #007700">, </span><span style="color: #0000BB">$ham2</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* hamdist is equivilent to: */<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">gmp_popcount</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_xor</span><span style="color: #007700">(</span><span style="color: #0000BB">$ham1</span><span style="color: #007700">, </span><span style="color: #0000BB">$ham2</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 6 6 </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.gmp-hamdist-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.gmp-popcount.html" class="function" rel="rdfs-seeAlso">gmp_popcount()</a> - Population count</span></li> <li class="member"> <span class="function"><a href="function.gmp-xor.html" class="function" rel="rdfs-seeAlso">gmp_xor()</a> - Bitwise XOR</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.gmp-gcdext.html">gmp_gcdext</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.gmp-init.html">gmp_init</a></div> <div class="up"><a href="ref.gmp.html">GMP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>