计划将二进制转换在C#中为十进制? [英] Program to convert binary to decimal in C#?

查看:112
本文介绍了计划将二进制转换在C#中为十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个基本程序,使我能够二进制数转换成十进制数,但其看上去几乎无处不在互联网上,我不能找到解决这个的作品!我似乎无法跟随的解决方案,到目前为止,我已经开发了一个位code,但不知道这是否是正确与否,任何帮助吗?谢谢

  INT iBinaryNum; //要存储二进制数
           串sDecimalNum; //要存储小数           Console.WriteLine(请输入要转换为十进制二进制数);
           iBinaryNum = Convert.ToInt32(到Console.ReadLine());           Console.WriteLine(您输入的二进制数+ iBinaryNum);
           sDecimalNum = Convert.ToString(iBinaryNum,2);           Console.WriteLine(这换算成十进制就是+ sDecimalNum);           // $ P从收盘$ pvent程序
           Console.WriteLine(preSS任意键关闭);
           Console.ReadKey();


解决方案

该Convert.ToInt32方法有哪些接受来自基地参数的重载。
http://msdn.microsoft.com/en-us/library/1k20k614.aspx

  iDecimalNum = Convert.ToInt32(binaryNumber,2);

显然你还没看够硬
如何二进制转换为十进制

I'm wanting to create a basic program to enable me to convert binary numbers into decimal numbers, but having looked almost everywhere on the internet, I just can't find a solution to this that works! I can't seem to follow the solutions, So far I've developed a bit of code, but not sure if it is correct or not, any help? Thanks

           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();

解决方案

The Convert.ToInt32 method has an overload which accepts a "from" base parameter. http://msdn.microsoft.com/en-us/library/1k20k614.aspx

iDecimalNum = Convert.ToInt32(binaryNumber, 2);

clearly you haven't looked hard enough How to convert binary to decimal

这篇关于计划将二进制转换在C#中为十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆