1 out of 1 rated this helpful - Rate this topic

# BigInteger.ModPow Method

.NET Framework 4.5

Performs modulus division on a number raised to the power of another number.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)
```public static BigInteger ModPow(
BigInteger value,
BigInteger exponent,
BigInteger modulus
)
```

#### Parameters

value
Type: System.Numerics.BigInteger

The number to raise to the exponent power.

exponent
Type: System.Numerics.BigInteger

The exponent to raise value by.

modulus
Type: System.Numerics.BigInteger

The number by which to divide value raised to the exponent power.

#### Return Value

Type: System.Numerics.BigInteger
The remainder after dividing valueexponent by modulus.
ExceptionCondition
DivideByZeroException

modulus is zero.

ArgumentOutOfRangeException

exponent is negative.

The ModPow method evaluates the following expression:

(baseValue ^ exponent) Mod modulus

To perform exponentiation on BigInteger values without modulus division, use the Pow method.

The following example provides a simple illustration of calling the ModPow method.

```using System;
using System.Numerics;

public class Class1
{
public static void Main()
{
BigInteger number = 10;
int exponent = 3;
BigInteger modulus = 30;
Console.WriteLine("({0}^{1}) Mod {2} = {3}",
number, exponent, modulus,
BigInteger.ModPow(number, exponent, modulus));
}
}
// The example displays the following output:
//      (10^3) Mod 30 = 10
```

#### .NET Framework

Supported in: 4.5, 4

Supported in: 4

#### Portable Class Library

Supported in: Portable Class Library

#### .NET for Windows Store apps

Supported in: Windows 8

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

#### Reference

Did you find this helpful?
(1500 characters remaining)
Show: