主题:请教高手,我写的用栈实现十进制转二进制出来的是乱码?
public static void Main(string[] args)
{
double a = Convert.ToDouble(Console.ReadLine());
double b= (int)a;
double c = a - b;
SeqQueue<double> q = new SeqQueue<double>();
string str = "";
SeqStack<double> s = new SeqStack<double>();
while (c <2)
{
q.enqueue((int)c);
c = c* 2;
}
str +=q.dequeue();
while (b != 0)
{
s.push(b % 2);
b = b / 2;
}
while (!s.isEmpty())
{
str += s.pop();
}
Console.WriteLine(str);
}
}
为什么出来的是乱码呢,我定义了顺序栈和顺序循环队列,以及相应的借口,运行没错误,但是出来的是乱码,改怎么改呢?请教高手啊~[em1]
{
double a = Convert.ToDouble(Console.ReadLine());
double b= (int)a;
double c = a - b;
SeqQueue<double> q = new SeqQueue<double>();
string str = "";
SeqStack<double> s = new SeqStack<double>();
while (c <2)
{
q.enqueue((int)c);
c = c* 2;
}
str +=q.dequeue();
while (b != 0)
{
s.push(b % 2);
b = b / 2;
}
while (!s.isEmpty())
{
str += s.pop();
}
Console.WriteLine(str);
}
}
为什么出来的是乱码呢,我定义了顺序栈和顺序循环队列,以及相应的借口,运行没错误,但是出来的是乱码,改怎么改呢?请教高手啊~[em1]