【发布时间】:2014-07-17 22:37:41
【问题描述】:
我尝试将数字转换为二进制数。所以这是我的代码:
static void Main(string[] args)
{
Console.WriteLine("Geben Sie eine Zahl ein, die convertiert werden soll!");
int a = Convert.ToInt16(Console.ReadLine());
string b = "";
while (a != 0)
{
if (a % 2 == 0)
{
b.Insert(b.Length, "0");
}
else
{
b.Insert(b.Length(), "1");
}
a = a / 2;
}
Console.WriteLine(b);
Console.ReadLine();
}
问题是,数字的顺序是错误的。所以我制作了一个字符串并将数字添加到最后一个位置。但是当我执行代码时没有任何反应......
【问题讨论】:
标签: c# string insert binary numbers