gmp_lib.mpn_set_str Method

GMP Native Interface for .NET

gmp_libmpn_set_str Method
Convert bytes {str, strsize} in the given base to limbs at rp.

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 mp_size_t mpn_set_str(
	mp_ptr rp,
	char_ptr str,
	size_t strsize,
	int base
)
Public Shared Function mpn_set_str ( 
	rp As mp_ptr,
	str As char_ptr,
	strsize As size_t,
	base As Integer
) As mp_size_t
public:
static mp_size_t mpn_set_str(
	mp_ptr^ rp, 
	char_ptr str, 
	size_t strsize, 
	int base
)
static member mpn_set_str : 
        rp : mp_ptr * 
        str : char_ptr * 
        strsize : size_t * 
        base : int -> mp_size_t 

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
str
Type: Math.Gmp.Nativechar_ptr
The operand string.
strsize
Type: Math.Gmp.Nativesize_t
The length of str.
base
Type: SystemInt32

Return Value

Type: mp_size_t
The number of limbs of rp.
Remarks

str[0] is the most significant input byte and str[strsize - 1] is the least significant input byte. Each byte should be a value in the range 0 to base - 1, not an ASCII character. base can vary from 2 to 256.

The converted value is {rp, rn} where rn is the return value. If the most significant input byte str[0] is non-zero, then rp[rn - 1] will be non-zero, else rp[rn - 1] and some number of subsequent limbs may be zero.

The area at rp has to have space for the largest possible number with strsize digits in the chosen base, plus one extra limb.

The input must have at least one byte, and no overlap is permitted between {str, strsize} and the result at rp.

Examples
// Create multi-precision operands.
mp_ptr rp = new mp_ptr(new uint[2]);
byte[] s = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 1 };
mp_ptr result = new mp_ptr(new uint[] { 0x00000001, 0x00000001 });
char_ptr str = new char_ptr("xxxxxxxxxxxxxxxxx");
Marshal.Copy(s, 0, str.ToIntPtr(), 9);

// Convert rp from str in hex base.
mp_size_t count = gmp_lib.mpn_set_str(rp, str, 9, 16);

// Assert the non-ASCII, hex representation of s1p.
Assert.IsTrue(count == rp.Size);
Assert.IsTrue(rp.SequenceEqual(result));

// Release unmanaged memory.
gmp_lib.free(rp);
gmp_lib.free(str);
' Create multi-precision operands.
Dim rp As New mp_ptr(New UInteger(1) { })
Dim s As Byte() = New Byte() { 1, 0, 0, 0, 0, 0, 0, 0, 1}
Dim result As New mp_ptr(New UInteger() { &H1, &H1})
Dim str As New char_ptr("xxxxxxxxxxxxxxxxx")
Marshal.Copy(s, 0, str.ToIntPtr(), 9)

' Convert rp from str in hex base.
Dim count As mp_size_t = gmp_lib.mpn_set_str(rp, str, 9, 16)

' Assert the non-ASCII, hex representation of s1p.
Assert.IsTrue(count = rp.Size)
Assert.IsTrue(rp.SequenceEqual(result))

' Release unmanaged memory.
gmp_lib.free(rp)
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.

See Also