-3

好的,在尝试了在其他问题和谷歌上找到的大量解决方案后,我似乎找不到解决这个问题的方法。这是我的代码,感谢您的帮助,它让我发疯,谢谢!

           int iBinaryNum; //To store binary number
           string sDecimalNum; //To store decimal numbers

           Console.WriteLine("Enter the binary number you want to convert to decimal");
           iBinaryNum = Convert.ToInt32(Console.ReadLine());

           Console.WriteLine("The Binary number you have entered is " + iBinaryNum);


           sDecimalNum = Convert.ToString(iBinaryNum, 2);

           Console.WriteLine("This converted into decimal is " + sDecimalNum);

           //Prevent program from closing
           Console.WriteLine("Press any key to close");
           Console.ReadKey();
4

1 回答 1

0

你有错误的方式

    static void Main(string[] args)
    {
        string sBinaryNum; //To store binary number
        int iDecimalNum; //To store decimal numbers

        Console.WriteLine("Enter the binary number you want to convert to decimal");
        sBinaryNum = Console.ReadLine();

        Console.WriteLine("The Binary number you have entered is " + sBinaryNum);


        iDecimalNum = Convert.ToInt32(sBinaryNum, 2);

        Console.WriteLine("This converted into decimal is " + iDecimalNum);

        //Prevent program from closing
        Console.WriteLine("Press any key to close");
        Console.ReadKey();
    }
于 2013-11-14T02:10:27.153 回答