【前置知识】
数据结构之栈
进制转换的数学计算方式
【代码实现】
using System;
using System.Collections;
namespace StackStruct
{
class StackApplication
{
public static void Decimalism2N(int number, int n)
{
Stack stack=new Stack();
int x = number;
char[] data = new char[16]
{
'0', '1', '2', '3',
'4','5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
while (number>0)
{
int remainder = (int) (number%n);
stack.Push(data[remainder]);
number /= n;
}
Console.Write("{0}转换成{1}进制为:",x,n);
while (stack.Count>0)
{
Console.Write(stack.Pop());
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackStruct
{
class Program
{
static void Main(string[] args)
{
StackApplication.Decimalism2N(123456789,16);
Console.ReadKey();
}
}
}