一、最简单的方法:
int value=9;
string outString=Convert.ToString(9,2);
二,简单算法实现:
Code
public static string ToBinaryString(int value)
{
string outString = string.Empty;
while (value > 0)
{
if (value % 2 == 0)
{
value = value / 2;
outString += "0";
}//end if
else
{
value = value / 2;
outString += "1";
}//end else
}//end while
string reverse = String.Empty;//逆转字符串
for (int i = outString.Length - 1; i > -1; i--)
{
reverse += outString[i];
}
return reverse;
}