gmp_lib.mpz_hamdist Method

GMP Native Interface for .NET

gmp_libmpz_hamdist Method
Return the hamming distance between the two operands.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static mp_bitcnt_t mpz_hamdist(
	mpz_t op1,
	mpz_t op2
)
Public Shared Function mpz_hamdist ( 
	op1 As mpz_t,
	op2 As mpz_t
) As mp_bitcnt_t
public:
static mp_bitcnt_t mpz_hamdist(
	mpz_t^ op1, 
	mpz_t^ op2
)
static member mpz_hamdist : 
        op1 : mpz_t * 
        op2 : mpz_t -> mp_bitcnt_t 

Parameters

op1
Type: Math.Gmp.Nativempz_t
The first operanf integer.
op2
Type: Math.Gmp.Nativempz_t
The second operanf integer.

Return Value

Type: mp_bitcnt_t
The hamming distance between the two operands.
Remarks

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.

Examples
// 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);
' Create, initialize, and set the value of op1 to 63.
Dim op1 As New mpz_t()
gmp_lib.mpz_init_set_ui(op1, 63UI)

' Create, initialize, and set the value of op2 to 70.
Dim op2 As New mpz_t()
gmp_lib.mpz_init_set_ui(op2, 70UI)

' Assert that the Hamming distance between op1 and op2 is 5.
Assert.IsTrue(gmp_lib.mpz_hamdist(op1, op2) = 5UI)

' Release unmanaged memory allocated for op1 and op2.
gmp_lib.mpz_clears(op1, op2, Nothing)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also