gmp_libmpz_get_str Method |
Namespace: Math.Gmp.Native
The base argument may vary from 2 to 62 or from −2 to −36.
For base in the range 2..36, digits and lower-case letters are used; for −2..−36, digits and upper-case letters are used; for 37..62, digits, upper-case letters, and lower-case letters (in that significance order) are used.
If str is char_ptr.Zero, the result string is allocated using the current allocation function. The block will be strlen(str)+1 bytes, that being exactly enough for the string and null-terminator.
If str is not char_ptr.Zero, it should point to a block of storage large enough for the result, that being mpz_sizeinbase(op, base) + 2. The two extra bytes are for a possible minus sign, and the null-terminator.
// Create, initialize, and set the value of x to -210. mpz_t x = new mpz_t(); gmp_lib.mpz_init_set_si(x, -210); // Retrieve the string value of x, and assert that it is "-210". char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, 10, x); Assert.IsTrue(s.ToString() == "-210"); // Release unmanaged memory allocated for x and the string value. gmp_lib.mpz_clear(x); gmp_lib.free(s);