我应该如何用科学计数法(+301)解析大量数字?

Cod*_*Red 3 c# console parsing

我试图解析答案,Math.Pow(2,1000)但最终只能得到相同的答案1.07150860718627E+301。我已经尝试使用BigIntegerdecimal.Parsedouble.TryParse。我希望将其存储在不带小数的数组中

Mar*_*ell 6

作为一个数字int[]

var value = BigInteger.Pow(2, 1000); // note: BigInteger.One << 1000 may be faster?
string s = value.ToString();
int[] digits = new int[s.Length];
for (int i = 0; i < digits.Length; i++)
    digits[i] = s[i] - '0';
Run Code Online (Sandbox Code Playgroud)

或者,如果您追求数字总和(注释):

var value = BigInteger.Pow(2, 1000); // note: BigInteger.One << 1000 may be faster?
string s = value.ToString();
int sum = 0;
foreach (char c in s) sum += c - '0';
Run Code Online (Sandbox Code Playgroud)

(请注意,这仅处理正值;对于负值,您需要对第一个字符进行特殊大小写)

但要强调:仅保留整体价值似乎更为自然BigInteger