好的,在尝试了其他问题和google上找到的大量解决方案之后,我似乎找不到解决这个问题的方法..这是我的代码,任何帮助表示感谢,它让我发疯,谢谢!
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();
答案 0 :(得分: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();
}