-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);
3

1 Answer 1

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.