Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 C# 中的堆栈创建程序以将二进制转换为十进制?
这是一个提示,此代码段使用堆栈将十进制整数转换为二进制,您只需反转过程:-P
int num = 50; Stack<int> stack = new Stack<int>(); while (num != 0) { stack.Push(num % 2); num /= 2; } while (stack.Count > 0) { Console.Write(stack.Pop()); }