gmp_lib.mpn_rshift Method

GMP Native Interface for .NET

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
)
Public Shared Function mpn_rshift ( 
	rp As mp_ptr,
	sp As mp_ptr,
	n As mp_size_t,
	count As UInteger
) As mp_limb_t
public:
static mp_limb_t mpn_rshift(
	mp_ptr^ rp, 
	mp_ptr^ sp, 
	mp_size_t n, 
	unsigned int count
)
static member mpn_rshift : 
        rp : mp_ptr * 
        sp : mp_ptr * 
        n : mp_size_t * 
        count : uint32 -> mp_limb_t 

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);
' Create multi-precision operands, and expected result.
Dim sp As New mp_ptr(New UInteger() { &HffffffffUI, &HffffffffUI})
Dim rp As New mp_ptr(New UInteger(1) { })
Dim result As New mp_ptr(New UInteger() { &HffffffffUI, &H7fffffff})

' Set rp = sp >> 1.
Dim bits As mp_limb_t = gmp_lib.mpn_rshift(rp, sp, sp.Size, 1)

' Assert result of operation.
Assert.IsTrue(bits = (If(gmp_lib.mp_bytes_per_limb = 4, &H80000000UI, &H8000000000000000UL)))
Assert.IsTrue(rp.SequenceEqual(result))

' Release unmanaged memory.
gmp_lib.free(rp, sp, result)

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