【问题标题】:I need big numeric variable in C#我需要 C# 中的大数值变量
【发布时间】:2016-06-30 20:25:46
【问题描述】:

我需要在 c# 的变量中保存 2 的 1024 次幂 我该怎么办? 我试过这个:

label1.Text = "0";
decimal res = 0;
res += System.Convert.ToDecimal(Math.Pow(2, 1024));
label1.Text = System.Convert.ToString(res);

【问题讨论】:

标签: c# variables integer


【解决方案1】:

您可以尝试使用BigInteger

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

此外,如果您使用的是 .Net BigInteger 类不可用的环境(例如针对 .Net 版本 2 的项目),您可以使用如下任何一个外部实现:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 2021-10-11
    相关资源
    最近更新 更多