C# 对于较大的数字,无法将二进制转换为十进制

C# 对于较大的数字,无法将二进制转换为十进制,c#,binary,bit-manipulation,binary-data,bits,C#,Binary,Bit Manipulation,Binary Data,Bits,我正在将二进制数转换成十进制数,直到我的数字超过$2^64$。这似乎是因为数据类型不能容纳大于$2^64$any insight的数字?发生的情况是,在处理巨大的二进制数时,存储在我的base_2变量中的数字似乎不能超过$2^64$,但它溢出了,因为数据类型太小,重置为0…有没有办法绕过或修复此问题 //Vector to store the Binary # that user has input List<ulong> binaryVector =

我正在将二进制数转换成十进制数,直到我的数字超过$2^64$。这似乎是因为数据类型不能容纳大于$2^64$any insight的数字?发生的情况是,在处理巨大的二进制数时,存储在我的base_2变量中的数字似乎不能超过$2^64$,但它溢出了,因为数据类型太小,重置为0…有没有办法绕过或修复此问题

        //Vector to store the Binary # that user has input
        List<ulong> binaryVector = new List<ulong>();

        //Vector to store the Decimal Vector I will output
        List<string> decimalVector = new List<string>();

        //Variable to store the input
        string input = "";

        //Variables to do conversions
        ulong base2 = 1;
        ulong decimalOutput = 0;

        Console.WriteLine("2^64=" + Math.Pow(2.00,64));

        //Prompt User
        Console.WriteLine("Enter the Binary Number you would like to convert to decimal: ");
        input = Console.ReadLine();

        //Store the user input in a vector
        for(int i = 0; i < input.Length; i++)
        {
            //If we find a 0, store it in the appropriate vector, otherwise we found a 1..
            if (input[i].Equals('0'))
            {
                binaryVector.Add(0);
            }
            else
            {
                binaryVector.Add(1);
            }
        }

        //Reverse the vector
        binaryVector.Reverse();

        //Convert the Binary # to Decimal
        for(int i = 0; i < binaryVector.Count; i++)
        {
            //0101 For Example: 0 + (0*1) = 0 Thus: 0 is out current Decimal
            //While our base2 variable is now a multiple of 2 (1 * 2 = 2)..
            decimalOutput = decimalOutput + (binaryVector[i] * base2);
            base2 = base2 * 2;
            Console.WriteLine("\nTest base2 Output Position[" + i + "]::" + base2);
        }

        //Convert Decimal Output to String
        string tempString = decimalOutput.ToString();
//用于存储用户输入的二进制文件的向量
List binaryVector=新列表();
//Vector以存储我将输出的十进制向量
列表小数向量=新列表();
//变量来存储输入
字符串输入=”;
//要进行转换的变量
ulong base2=1;
ulong小数输出=0;
Console.WriteLine(“2^64=“+Math.Pow(2.00,64));
//提示用户
WriteLine(“输入要转换为十进制的二进制数:”;
input=Console.ReadLine();
//将用户输入存储在向量中
for(int i=0;i
一个
ulong
只能保存0到2**64之间的值;看


当您想处理更大的价值时,请使用a。

谢谢。我所要做的就是加上一个参考系。数值,然后把我的uLong改成大整数。