-3

I need to save power 1024 of 2 in a variable in c# what should i do? i tried this :

label1.Text = "0";
decimal res = 0;
res += System.Convert.ToDecimal(Math.Pow(2, 1024));
label1.Text = System.Convert.ToString(res);
user1666620
  • 4,800
  • 18
  • 27
Mani
  • 11
  • 2
  • 3
    Possible duplicate of [working with incredibly large numbers in .NET](http://stackoverflow.com/questions/279038/working-with-incredibly-large-numbers-in-net) – Matt Rowland Jun 30 '16 at 20:28
  • Use a BigInteger - https://msdn.microsoft.com/en-us/library/system.numerics.biginteger(v=vs.110).aspx – Rick Jun 30 '16 at 20:29
  • That's a gigantic number. It's going to have more than 300 digits. I hope your label is really long. – Jim Mischel Jun 30 '16 at 20:44

1 Answers1

4

You can try to use a BigInteger

var exponentiated = BigInteger.Pow(2, 1024);
var newText = exponentiated.ToString();

Also, if you are using an environment where the .Net BigInteger class is not available (a project targeting .Net version 2 for example), you can use an external implementation like any of these:

mishamosher
  • 1,003
  • 1
  • 13
  • 28