gmp_libmpz_hamdist Method |
Namespace: Math.Gmp.Native
If op1 and op2 are both ≥ 0 or both < 0, return the hamming distance between the two operands, which is the number of bit positions where op1 and op2 have different bit values. If one operand is ≥ 0 and the other < 0 then the number of bits different is infinite, and the return value is the largest possible mp_bitcnt_t.
The function behaves as if twos complement arithmetic were used (although sign-magnitude is the actual implementation). The least significant bit is number 0.
// Create, initialize, and set the value of op1 to 63. mpz_t op1 = new mpz_t(); gmp_lib.mpz_init_set_ui(op1, 63U); // Create, initialize, and set the value of op2 to 70. mpz_t op2 = new mpz_t(); gmp_lib.mpz_init_set_ui(op2, 70U); // Assert that the Hamming distance between op1 and op2 is 5. Assert.IsTrue(gmp_lib.mpz_hamdist(op1, op2) == 5U); // Release unmanaged memory allocated for op1 and op2. gmp_lib.mpz_clears(op1, op2, null);