using System;
using System.IO;
namespace TwoReturnTen
{
class Program
{
static void Main(string[] args)
{
object o1 = 11;
//二进制转十进制的算法
string str = "0110001";
int tmp = 0; int x = 1; for (int i = str.Length - 1; i >= 0; i--)
{
if (str.Substring(i, 1) == "1")
{
x = 1; for (int k = 0; k < str.Length - i - 1; k++)
{ x *= 2; }
tmp += x;
}
}
Console.WriteLine("十进制为:" + tmp);
//十进制转二进制的类库
TENToBIN(int.Parse(str));
Console.WriteLine("二进制为" + str);
Console.WriteLine(2 ^ 2);
}
/// <summary>
///十进制转二进制的类库
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static string TENToBIN(int x)
{
return Convert.ToString(x, 2);
}
}
}