简体   繁体   English

对于 UInt64,值太大或太小

[英]Value was either too large or too small for a UInt64

I have this code that i am trying to use to convert string of binary to decimal value.我有这段代码,我试图用它来将二进制字符串转换为十进制值。 However, i am getting the following error:但是,我收到以下错误:

Value was either too large or too small for a UInt64.对于 UInt64,值太大或太小。

string a = "10100000100100110110010000010101111011011001101110111111111101000000101111001110001111100001101";
ulong value = Convert.ToUInt64(a, 2);
Console.WriteLine(value);

I have tried every possible solution available on the inte.net, but i'm still not getting the proper solution.我已经尝试了 inte.net 上可用的所有可能的解决方案,但我仍然没有得到正确的解决方案。

That string is 96 characters.该字符串是96 个字符。 So it represents 96 bits.所以它代表96位。 You are trying to fit that into a UInt64 that, not surprisingly, can hold 64 bits only.您正在尝试将其放入UInt64中,毫不奇怪,它只能容纳64位。

You can use a BigInteger for arbitrary large numbers.您可以将BigInteger用于任意大的数字。

https://learn.microsoft.com/en-us/do.net/api/system.numerics.biginteger?view.net-7.0 https://learn.microsoft.com/en-us/do.net/api/system.numerics.biginteger?view.net-7.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM