コード例 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (!Input.Text.ToString().Contains("-"))
         {
             string temp = "";
             if (!Input.Text.Contains("."))
             {
                 temp = Instruments.IntChoice(Convert.ToInt32(comboBox1.SelectedItem),
                                              Convert.ToInt32(comboBox2.SelectedItem), Input.Text);
             }
             else if (Input.Text[0].ToString() == "0" & Input.Text[1].ToString() == ".")
             {
                 temp = Instruments.FractChoice(Convert.ToInt32(comboBox1.SelectedItem),
                                                Convert.ToInt32(comboBox2.SelectedItem), Input.Text);
             }
             else if (Input.Text[0].ToString() != "0" & Input.Text.Contains("."))
             {
                 temp = MixedSolution.MixedInput(Convert.ToInt32(comboBox1.SelectedItem),
                                                 Convert.ToInt32(comboBox2.SelectedItem), Input.Text);
             }
             Output.Text = temp;
             label4.Text = "Output base " + comboBox2.SelectedItem.ToString() + " value:";
         }
         else
         {
             MessageBox.Show("You can only use positive values");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
コード例 #2
0
        // int values - division method
        public static string DecimalToBinary(string input)
        {
            int        intInput;
            List <int> binaryRepository = new List <int>();
            bool       check            = Int32.TryParse(input, out intInput);

            // if temp = 1 then it is the end of dividing
            while (intInput != 1 & check)
            {
                var a = intInput % 2;
                binaryRepository.Add(a);
                if (a == 1)
                {
                    intInput--;
                    intInput /= 2;
                }
                else
                {
                    intInput /= 2;
                }
            }
            binaryRepository.Add(1);
            binaryRepository.Reverse();
            return(Instruments.ListToString(binaryRepository));
        }
コード例 #3
0
        public static string DecimalToOctal(string input)
        {
            int        intInput;
            List <int> repository = new List <int>();
            bool       check      = Int32.TryParse(input, out intInput);

            while (intInput > 8 & check)
            {
                var a = intInput % 8;
                repository.Add(a);
                if (a == 0)
                {
                    intInput /= 8;
                }
                else
                {
                    while (intInput % 8 != 0)
                    {
                        intInput--;
                    }
                    intInput /= 8;
                }
            }
            repository.Add(intInput % 8);
            repository.Reverse();
            return(Instruments.ListToString(repository));
        }
コード例 #4
0
        public static string DecimalToOctal(string input)
        {
            DigitRemainderCount(input);
            List <int> repository = new List <int>();
            double     temp       = Convert.ToDouble(input);

            while (repository.Count <= digit)
            {
                var check = temp * 8;
                repository.Add((int)check);
                if (check > 1)
                {
                    while (check > 1)
                    {
                        check--;
                    }
                    temp = check;
                }
                else
                {
                    temp = check;
                }
            }
            return("0." + Instruments.ListToString(repository));
        }
コード例 #5
0
        public static string MixedInput(int from, int to, string input)
        {
            string[] twoPartsOfInputRepository = input.Split(new char[] { ',', '.' });
            string   left, right;

            left  = Instruments.IntChoice(from, to, twoPartsOfInputRepository[0]) + ".";
            right = Instruments.FractChoice(from, to, ("0." + twoPartsOfInputRepository[1]));
            for (int i = 2; i < right.Length; i++)
            {
                left += right[i].ToString();
            }
            return(left);
        }
コード例 #6
0
        public static string DecimalToHexa(string input)
        {
            int    intInput;
            string repository = "";
            bool   check      = Int32.TryParse(input, out intInput);

            while (intInput > 16 & check)
            {
                var a = intInput % 16;
                switch (a)
                {
                case 10:
                    repository += "A";
                    break;

                case 11:
                    repository += "B";
                    break;

                case 12:
                    repository += "C";
                    break;

                case 13:
                    repository += "D";
                    break;

                case 14:
                    repository += "E";
                    break;

                case 15:
                    repository += "F";
                    break;

                default:
                    repository += a.ToString();
                    break;
                }
                if (a == 0)
                {
                    intInput /= 16;
                }
                else
                {
                    while (intInput % 16 != 0)
                    {
                        intInput--;
                    }
                    intInput /= 16;
                }
            }
            switch (intInput % 16)
            {
            case 10:
                repository += "A";
                break;

            case 11:
                repository += "B";
                break;

            case 12:
                repository += "C";
                break;

            case 13:
                repository += "D";
                break;

            case 14:
                repository += "E";
                break;

            case 15:
                repository += "F";
                break;

            default:
                repository += (intInput % 16).ToString();
                break;
            }
            return(Instruments.StringReverce(repository));
        }