Click or drag to resize
gmp_libmpn_get_str Method
Convert {s1p, s1n} to a raw unsigned char array at str in base base, and return the number of characters produced.

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 size_t mpn_get_str(
	char_ptr str,
	int base,
	mp_ptr s1p,
	mp_size_t s1n
)

Parameters

str
Type: Math.Gmp.Nativechar_ptr
The result string.
base
Type: SystemInt32
The base.
s1p
Type: Math.Gmp.Nativemp_ptr
The operand integer.
s1n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of s1p.

Return Value

Type: size_t
The number of characters produced at str.
Remarks

There may be leading zeros in the string. The string is not in ASCII; to convert it to printable format, add the ASCII codes for "0" or "A", depending on the base and range. base can vary from 2 to 256.

The most significant limb of the input {s1p, s1n} must be non-zero. The input {s1p, s1n} is clobbered, except when base is a power of 2, in which case it’s unchanged.

The area at str has to have space for the largest possible number represented by a s1n long limb array, plus one extra character.

Examples
// Create multi-precision operands.
mp_ptr s1p = new mp_ptr(new uint[] { 0x00000001, 0x00000001 });
char_ptr str = new char_ptr("xxxxxxxxxxxxxxxxx");

// Convert s1p to hex string.
size_t count = gmp_lib.mpn_get_str(str, 16, s1p, s1p.Size);

// Copy out str to bytes.
byte[] s = new byte[count];
Marshal.Copy(str.ToIntPtr(), s, 0, (int)count);

// Assert the non-ASCII, hex representation of s1p.
Assert.IsTrue(s.SequenceEqual(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 1 }));

// Release unmanaged memory.
gmp_lib.free(s1p);
gmp_lib.free(str);
See Also