Speed up development with full-stack environments for every branch.

Learn More

Calculate the hamming distance between two GMP numbers [PHP]

9 Runs 27 Views 2 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
/*
 * PHP GMP -  Calculate the hamming distance between two GMP numbers
 */

$ham1 = gmp_init("1001010011", 2);
$ham2 = gmp_init("1011111100", 2);
echo gmp_hamdist($ham1, $ham2) . "\n";

/* hamdist is equivilent to: */
echo gmp_popcount(gmp_xor($ham1, $ham2)) . "\n";
?>

Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).