Click or drag to resize
gmp_libmpz_popcount Method
Return the population count of op.

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_popcount(
	mpz_t op
)

Parameters

op
Type: Math.Gmp.Nativempz_t
The operand integer.

Return Value

Type: mp_bitcnt_t
If op ≥ 0, return the population count of op, which is the number of 1 bits in the binary representation. If op < 0, the number of 1s is infinite, and the return value is the largest possible mp_bitcnt_t.
Remarks

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 op to 63.
mpz_t op = new mpz_t();
gmp_lib.mpz_init_set_ui(op, 63U);

// Assert that op has 6 one bits.
Assert.IsTrue(gmp_lib.mpz_popcount(op) == 6U);

// Release unmanaged memory allocated for op.
gmp_lib.mpz_clears(op);
See Also