Click or drag to resize
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
)

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);
See Also