コード例 #1
0
 /// <summary>
 /// 初始化类。
 /// </summary>
 static UiUtil()
 {
     HexToDec.Add('0', 0);
     HexToDec.Add('1', 1);
     HexToDec.Add('2', 2);
     HexToDec.Add('3', 3);
     HexToDec.Add('4', 4);
     HexToDec.Add('5', 5);
     HexToDec.Add('6', 6);
     HexToDec.Add('7', 7);
     HexToDec.Add('8', 8);
     HexToDec.Add('9', 9);
     HexToDec.Add('a', 10);
     HexToDec.Add('b', 11);
     HexToDec.Add('c', 12);
     HexToDec.Add('d', 13);
     HexToDec.Add('e', 14);
     HexToDec.Add('f', 15);
     HexToDec.Add('A', 10);
     HexToDec.Add('B', 11);
     HexToDec.Add('C', 12);
     HexToDec.Add('D', 13);
     HexToDec.Add('E', 14);
     HexToDec.Add('F', 15);
 }
コード例 #2
0
        static void Main()
        {
            Console.WriteLine("Enter the numeral base of the your number (2, 10 or 16): ");
            int numBase = int.Parse(Console.ReadLine());

            Console.WriteLine("and numeral base in which you want your number to be converted (2, 10 or 16): ");
            int newBase = int.Parse(Console.ReadLine());

            while (numBase == newBase)
            {
                Console.WriteLine("Incorrect input! Equal numeral systems!");
                Console.WriteLine("Enter the numeral base of the first number (2, 10 or 16): ");
                numBase = int.Parse(Console.ReadLine());

                Console.WriteLine("and numeral base of the second number (2, 10 or 16): ");
                newBase = int.Parse(Console.ReadLine());
            }

            if (numBase == 10 && newBase == 2)
            {
                ConvertDecimal.Main();
            }

            if (numBase == 2 && newBase == 10)
            {
                BinToDec.Main();
            }

            if (numBase == 10 && newBase == 16)
            {
                DecToHex.Main();
            }

            if (numBase == 16 && newBase == 10)
            {
                HexToDec.Main();
            }

            if (numBase == 16 && newBase == 2)
            {
                HexToBin.Main();
            }

            if (numBase == 2 && newBase == 16)
            {
                BinToHex.Main();
            }
        }