Click or drag to resize
gmp_libmpn_rshift Method
Shift {sp, n} right by count bits, and write the result to {rp, n}.

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_limb_t mpn_rshift(
	mp_ptr rp,
	mp_ptr sp,
	mp_size_t n,
	uint count
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
sp
Type: Math.Gmp.Nativemp_ptr
The operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of sp and rp.
count
Type: SystemUInt32

Return Value

Type: mp_limb_t
The bits shifted out at the right are returned in the most significant count bits of the return value (the rest of the return value is zero).
Remarks

count must be in the range 1 to mp_bits_per_limb - 1. The regions {sp, n} and {rp, n} may overlap, provided rpsp.

This function is written in assembly for most CPUs.

Examples
// Create multi-precision operands, and expected result.
mp_ptr sp = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff });
mp_ptr rp = new mp_ptr(new uint[2]);
mp_ptr result = new mp_ptr(new uint[] { 0xffffffff, 0x7fffffff });

// Set rp = sp >> 1.
mp_limb_t bits = gmp_lib.mpn_rshift(rp, sp, sp.Size, 1);

// Assert result of operation.
Assert.IsTrue(bits == (gmp_lib.mp_bytes_per_limb == 4 ? 0x80000000 : 0x8000000000000000));
Assert.IsTrue(rp.SequenceEqual(result));

// Release unmanaged memory.
gmp_lib.free(rp, sp, result);
See Also