The `modPow()` method returns this BigInt to the power of `exponent` modulo `modulus`.
The syntax of BigInt.modPow() method is:
BigInt modPow(BigInt exponent BigInt modulus)
This modPow() method of BigInt returns this integer to the power of exponent
modulo modulus
.
Parameter | Optional/Required | Description |
---|---|---|
exponent | required | the exponent |
modulus | required | the modulus |
BigInt.modPow() returns value of type BigInt
.
In this example,
base
, an exponent BigInt exponent
, and a modulus BigInt modulus
.modPow()
method to calculate the result of base^exponent mod modulus
.void main() {
BigInt base = BigInt.from(2);
BigInt exponent = BigInt.from(10);
BigInt modulus = BigInt.from(7);
BigInt result = base.modPow(exponent, modulus);
print('Result of 2^10 mod 7: $result');
}
Result of 2^10 mod 7: 2
In this example,
base
, an exponent BigInt exponent
, and a modulus BigInt modulus
.modPow()
method to calculate the result of base^exponent mod modulus
.void main() {
BigInt base = BigInt.from(3);
BigInt exponent = BigInt.from(25);
BigInt modulus = BigInt.from(5);
BigInt result = base.modPow(exponent, modulus);
print('Result of 3^25 mod 5: $result');
}
Result of 3^25 mod 5: 3
In this example,
base
, an exponent BigInt exponent
, and a modulus BigInt modulus
.modPow()
method to calculate the result of base^exponent mod modulus
.void main() {
BigInt base = BigInt.from(5);
BigInt exponent = BigInt.from(3);
BigInt modulus = BigInt.from(13);
BigInt result = base.modPow(exponent, modulus);
print('Result of 5^3 mod 13: $result');
}
Result of 5^3 mod 13: 8
In this Dart tutorial, we learned about modPow() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.