gmp_libmpn_get_str 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 mpn_get_str( char_ptr str, int base, mp_ptr s1p, mp_size_t s1n )
Public Shared Function mpn_get_str ( str As char_ptr, base As Integer, s1p As mp_ptr, s1n As mp_size_t ) As size_t
public: static size_t mpn_get_str( char_ptr str, int base, mp_ptr^ s1p, mp_size_t s1n )
static member mpn_get_str : str : char_ptr * base : int * s1p : mp_ptr * s1n : mp_size_t -> size_t
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_tThe number of characters produced at str.

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.

// 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);
' Create multi-precision operands. Dim s1p As New mp_ptr(New UInteger() { &H1, &H1}) Dim str As New char_ptr("xxxxxxxxxxxxxxxxx") ' Convert s1p to hex string. Dim count As size_t = gmp_lib.mpn_get_str(str, 16, s1p, s1p.Size) ' Copy out str to bytes. Dim s As Byte() = New Byte(count - 1) { } Marshal.Copy(str.ToIntPtr(), s, 0, CInt(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)
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.
