http://bbs.csdn.net/topics/380131393
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox3.Text = Convert(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
}
private string Convert(int n, int Base)
{
bool gt0 = true;
if (Base < 10 || Base > 36) return null;
if (n == 0) return "0";
if (n < 0)
{
n = -n;
gt0 = false;
}
StringBuilder sb = new StringBuilder();
string t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
while (n > 0)
{
sb.Append(t[n % Base]);
n /= Base;
}
t = sb.ToString();
n = t.Length;
sb.Length = 0;
if (!gt0) sb.Append("-");
while (--n >= 0) sb.Append(t[n]);
return sb.ToString();
}
}
}