Winform——計算機進数変換

21700 ワード

namespace  2._0

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        public string Shizhuaner(int a, int jinzhi) // 

        {

            string jieguo = "";

            while (true)

            {

                string s = (a % jinzhi).ToString(); //s a%2 , 2。

                jieguo = s + jieguo; //s 

                a = a / jinzhi;

                if (a == 0)

                {

                    break;

                }



            }

            return jieguo;

        }



        private void button1_Click(object sender, EventArgs e) // 

        {

            string x = Shizhuanba(int.Parse(textBox1.Text), 2);

            textBox2.Text = x;

        }



        public string Shizhuanba(int a, int jinzhi) // 

        {

            string jieguo = "";

            while (true)

            {

                string s = (a % jinzhi).ToString();

                jieguo = s + jieguo;

                a = a / jinzhi;

                if (a == 0)

                {

                    break;

                }



            }

            return jieguo;

        }



        private void button2_Click(object sender, EventArgs e) // 

        {

            string x = Shizhuanba(int.Parse(textBox1.Text), 8);

            textBox3.Text = x;

        }



        public string Shizhuanshiliu(int a,int jinzhi) // 

        {

            string jieguo = "";

                while (true)

                {

                    int yushu = a % jinzhi;

                    string s = "";

                    if(yushu==10)

                    {

                        s = "A";

                    }

                    else if (yushu == 11)

                    {

                        s = "B";

                    }

                    else if (yushu == 12)

                    {

                        s = "C";

                    }

                    else if (yushu == 13)

                    {

                        s = "D";

                    }

                    else if (yushu == 14)

                    {

                        s = "E";

                    }

                    else if (yushu == 15)

                    {

                        s = "F";

                    }

                    else

                    {

                        s = yushu.ToString();

                    }

                    jieguo = s + jieguo;

                    a = a / jinzhi;

                    if (a == 0)

                    {

                        break;

                    }

                }

            return jieguo;

        }



        private void button3_Click(object sender, EventArgs e) // 

        {

            string x = Shizhuanshiliu(int.Parse(textBox1.Text), 16);

            textBox4.Text = x;

        }



        private void button7_Click(object sender, EventArgs e) // 

        {

            textBox1.Text = "";

            textBox2.Text = "";

            textBox3.Text = "";

            textBox4.Text = "";

            textBox5.Text = "";

            textBox6.Text = "";

            textBox7.Text = "";

        }







        public string Erzhuanshi(string a)  // 

        {

            string jieguo = "";

            int length=a.Length;

            int Sum = 0;

            int n = 0;

            while (true)

            {  

                double y = int.Parse(a.Substring(length - 1, 1)) *Math.Pow(2,n);  

                length--;

                n++;

                int y1 = (int)y;

                Sum =Sum+y1 ;

                jieguo = Sum.ToString(); 

                if(length==0)

                {

                    break;

                }

            }  

            return jieguo;

        }

        private void button6_Click(object sender, EventArgs e) // 

        {



            string s = Erzhuanshi(textBox2.Text);

            textBox5.Text = s;

        }





        public string Bazhuanshi(string a)  // 

        {

            string jieguo = "";

            int length = a.Length;

            int Sum = 0;

            int n = 0;

            while (true)

            {

                double y = int.Parse(a.Substring(length - 1, 1)) * Math.Pow(8, n);

                length--;

                n++;

                int y1 = (int)y;

                Sum = Sum + y1;

                jieguo = Sum.ToString();

                if (length == 0)

                {

                    break;

                }

            }

            return jieguo;

        }



        private void button5_Click(object sender, EventArgs e) // 

        {

            string s = Bazhuanshi(textBox3.Text);

            textBox6.Text = s;

        }





        public string shiliuzhuanshi(string a)  // 

        {

            string jieguo = "";

            int length = a.Length;

            int Sum = 0;

            int n = 0;

           

            

            while (true)

            {   

                 /*

                 A 10

                 B 11

                 C 12

                 D 13

                 E 14

                 F 15

                 */ 

                string z = a.Substring(length - 1, 1);

                if(z=="A")

                {

                    z = "10";

                }

                else if (z == "B")

                {

                    z = "11";

                }

                else if (z == "C")

                {

                    z = "12";

                }

                else if (z == "D")

                {

                    z = "13";

                }

                else if (z == "E")

                {

                    z = "14";

                }

                else if (z == "F")

                {

                    z = "15";

                }

                else

                { 

                

                }

                double y = double.Parse(z) * Math.Pow(16, n);

                length--;

                n++;

                int y1 = (int)y;

                Sum = Sum + y1;

                jieguo = Sum.ToString();

                if (length == 0)

                {

                    break;

                }

            }

            return jieguo;

        }

        private void button4_Click(object sender, EventArgs e) // 

        {

            string s = shiliuzhuanshi(textBox4.Text);

            textBox7.Text = s;

        }

    }

}