GMP Native Interface for .NET
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)

public static mp_bitcnt_t mpz_popcount( mpz_t op )
Public Shared Function mpz_popcount ( op As mpz_t ) As mp_bitcnt_t
public: static mp_bitcnt_t mpz_popcount( mpz_t^ op )
static member mpz_popcount : op : mpz_t -> mp_bitcnt_t
Parameters
- op
- Type: Math.Gmp.Nativempz_t
The operand integer.
Return Value
Type: mp_bitcnt_tIf 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.

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 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);
' Create, initialize, and set the value of op to 63. Dim op As New mpz_t() gmp_lib.mpz_init_set_ui(op, 63UI) ' Assert that op has 6 one bits. Assert.IsTrue(gmp_lib.mpz_popcount(op) = 6UI) ' Release unmanaged memory allocated for op.
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.
