进制转换

amespace 进制转换
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.textBox2.Text = zhuanhua(Convert.ToInt32(this.textBox1.Text), 2);
            this.textBox3.Text = zhuanhua(Convert.ToInt32(this.textBox1.Text), 8);
            this.textBox4.Text = zhuanhua(Convert.ToInt32(this.textBox1.Text), 16);
        }
        public string zhuanhua(int a,int jinzhi) 
        {
            string s = "";
            while (true)
            {
                string m =( a % jinzhi).ToString();
                if (m == "10")
                {
                    m = "A";
                }
                else if (m=="11")
                {
                    m = "B";
                }
                else if (m == "12")
                {
                    m = "C";
                }
                else if (m == "13")
                {
                    m = "D";
                }
                else if (m == "14")
                {
                    m = "E";
                }
                else if (m == "15")
                {
                    m = "F";
                }
                s = m + s;
                a = a / jinzhi;
               
                if(a==0)
                {break;}
            }
            return s;        
        }
    }
}
原文地址:https://www.cnblogs.com/lushixiong/p/4536285.html