Пример #1
0
        }         //end of DecimalToOctal()

        public static void decimalToHexadecimal()
        {
            int    integer      = 0;
            string binaryNumber = "";

            try {
                do
                {
                    Console.Write("Enter A Decimal : ");
                    integer = Int32.Parse(Console.ReadLine());
                } while(integer < 0);
                while (integer > 1)
                {
                    binaryNumber += HexadecimalNumber.getCharacter((integer % 16));
                    integer      /= 16;
                }                 //end of while loop
                if (integer > 0)
                {
                    binaryNumber += HexadecimalNumber.getCharacter(integer);
                }                 //end of if statement
                Console.Write("Octal Number : ");
                for (int bn = binaryNumber.Length; bn > 0; bn--)
                {
                    Console.Write(binaryNumber.Substring(bn - 1, 1));
                }                 //end of for loop
                Console.WriteLine();
            } catch (Exception exception) {
                Console.WriteLine("Invalid Input");
            } //end of try catch block
        }     //end of decimalToHexadecimal()
Пример #2
0
        static void Main(string[] args)
        {
            int choice = -1;

            while (choice != 7)
            {
                Console.WriteLine("Options");
                Console.WriteLine("1.  Decimal To Binary");
                Console.WriteLine("2.  Binary To Decimal");
                Console.WriteLine("3.  Decimal To Octal");
                Console.WriteLine("4.  Octal To Decimal");
                Console.WriteLine("5.  Decimal To Hexadecimal");
                Console.WriteLine("6.  Hexadecimal To Decimal");
                Console.WriteLine("7.  Quit");
                do
                {
                    try {
                        Console.Write("Enter Choice : ");
                        choice = Int32.Parse(Console.ReadLine());
                    }
                    catch (Exception e) {
                        Console.WriteLine("Invalid Input");
                    }                     //end of try catch block
                }while(choice < 1 || choice > 7);
                switch (choice)
                {
                case 1:
                    DecimalNumber.decimalToBinary();
                    break;

                case 2:
                    BinaryNumber.binaryToDecimal();
                    break;

                case 3:
                    DecimalNumber.decimalToOctal();
                    break;

                case 4:
                    OctalNumber.octalToDecimal();
                    break;

                case 5:
                    DecimalNumber.decimalToHexadecimal();
                    break;

                case 6:
                    HexadecimalNumber.hexadecimalToDecimal();
                    break;
                }         //end of switch statement
            }             //end of while loop
        }