gmp_libmpz_sizeinbase Method |
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static size_t mpz_sizeinbase( mpz_t op, int base )
Public Shared Function mpz_sizeinbase ( op As mpz_t, base As Integer ) As size_t
public: static size_t mpz_sizeinbase( mpz_t^ op, int base )
static member mpz_sizeinbase : op : mpz_t * base : int -> size_t
Parameters
- op
- Type: Math.Gmp.Nativempz_t
The operand integer - base
- Type: SystemInt32
The base.
Return Value
Type: size_tThe size of op measured in number of digits in the given base.

base can vary from 2 to 62. The sign of op is ignored, just the absolute value is used. The result will be either exact or 1 too big. If base is a power of 2, the result is always exact. If op is zero the return value is always 1.
This function can be used to determine the space required when converting op to a string. The right amount of allocation is normally two more than the value returned by mpz_sizeinbase, one extra for a minus sign and one for the null-terminator.
It will be noted that mpz_sizeinbase(op, 2) can be used to locate the most significant 1 bit in op, counting from 1. (Unlike the bitwise functions which start from 0, see GNU MP - Logical and Bit Manipulation Functions.)

// Create, initialize, and set the value of op to 10000. mpz_t op = new mpz_t(); gmp_lib.mpz_init_set_si(op, 10000); // Assert size in different bases. Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 2) == 14); Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 8) == 5); Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 10) == 5); Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 16) == 4); // Release unmanaged memory allocated for op. gmp_lib.mpz_clear(op);
' Create, initialize, and set the value of op to 10000. Dim op As New mpz_t() gmp_lib.mpz_init_set_si(op, 10000) ' Assert size in different bases. Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 2) = 14) Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 8) = 5) Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 10) = 5) Assert.IsTrue(gmp_lib.mpz_sizeinbase(op, 16) = 4) ' Release unmanaged memory allocated for op. gmp_lib.mpz_clear(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.
