Assume that you have big integers like 1253999939979969998746 and 9999999999. Is there anyway to multiply these big integers in C#?
Note: I've tried System.Numerics.BigInteger
class constructor compiler says that integer is too long.
What's your suggestion?
p.s warn me if this question out of topics.
You need to use BigInteger.Parse
.
BigInteger num = BigInteger.Parse("1253999939979969998746");
If you try to use an integer value like below
BigInteger num = 1253999939979969998746;
the right hand side needs to have a type, which by default will be an Int32
or a long
. But since the number is too large to be an Int32
or a long
, the conversion fails, hence the error you get.
As Tim Schmelter pointed out in a comment, to then do your multiplication, you can do the following:
BigInteger num = BigInteger.Multiply(BigInteger.Parse("1253999939979969998746"),
BigInteger.Parse("9999999999"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With