/// <summary>
/// 十进制转换为二进制
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static string DecToBin(string x)
{
string z = null;
int X = Convert.ToInt32(x);
int i = 0;
long a, b = 0;
while (X > 0)
{
a = X%2;
X = X/2;
b = b + a*Pow(10, i);
i++;
}
z = Convert.ToString(b);
return z;
}
/// <summary>
/// 二进制转换为十进制
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static string BinToDec(string x)
{
string z = null;
int X = Convert.ToInt32(x);
int i = 0;
long a, b = 0;
while (X > 0)
{
a = X%10;
X = X/10;
b = b + a*Pow(2, i);
i++;
}
z = Convert.ToString(b);
return z;
}