Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AnyOtherNumSys
- {
- //Binary to decimal
- static void BinToDec()
- {
- Console.WriteLine("Enter your binary number:");
- string value = Console.ReadLine();
- int num = Convert.ToInt32(value, 2);
- Console.WriteLine("Binary {0} converted to dec {1}.", value, num.ToString());
- }
- //Binary to hexadecimal
- static void BinToHex()
- {
- Console.WriteLine("Enter your binary number:");
- string num = Console.ReadLine();
- int decNum = Convert.ToInt32(num, 2);
- string decInHex = decNum.ToString("x");
- Console.WriteLine("Hexadecimal representation: {0}", decInHex);
- }
- //hexadecimal to decimal
- static void HexToDec()
- {
- Console.WriteLine("Enter your hexadecimal number:");
- string value = Console.ReadLine();
- int num = Convert.ToInt32(value, 16);
- Console.WriteLine("Hex 0x{0} converted to dec {1}.", value, num.ToString());
- }
- //hexadecimal to binary
- static void HexToBin()
- {
- Console.WriteLine("Enter your hexadecimal number:");
- string temp = Console.ReadLine();
- int num = Convert.ToInt32(temp, 16);
- string dec = Convert.ToString(num, 2);
- Console.WriteLine("Binary representation {0} ", dec);
- }
- //decimal to binary
- static void DecToBin()
- {
- Console.WriteLine("Enter your decimal number:");
- int dec = int.Parse(Console.ReadLine());
- Console.WriteLine("Binary representation {0} ",Convert.ToString(dec, 2));
- }
- //decimal to hexadecimal
- static void DecToHex()
- {
- Console.WriteLine("Enter your decimal number:");
- int dec = int.Parse(Console.ReadLine());
- string decInHex = dec.ToString("x");
- Console.WriteLine("Hexadecimal representation "+ decInHex);
- }
- //choises
- static void Choise(string choise, string changeTo)
- {
- switch (choise)
- {
- case "1":
- if (changeTo == "3")
- {
- Console.WriteLine("Convert to decimal");
- BinToDec();
- }
- if (changeTo == "2")
- {
- Console.WriteLine("Convert to hexadecimal");
- BinToHex();
- }
- break;
- case "2":
- if (changeTo == "3")
- {
- Console.WriteLine("Convert to decimal");
- HexToDec();
- }
- if (changeTo == "1")
- {
- Console.WriteLine("Convert to binary");
- HexToBin();
- }
- break;
- case "3":
- if (changeTo == "1")
- {
- Console.WriteLine("Convert to binary");
- DecToBin();
- }
- if (changeTo == "2")
- {
- Console.WriteLine("Convert to hexadecimal");
- DecToHex();
- }
- break;
- default:
- Console.WriteLine("Wrong Choise!");
- Main();
- break;
- }
- }
- static void Main()
- {
- Console.WriteLine("Choose a numeral system:\r\n1.Binary\r\n2. Hexadecimal\r\n3. Decimal");
- string makeChoise = Console.ReadLine();
- Console.Write("Convert to: ");
- string changeTo = Console.ReadLine();
- Choise(makeChoise, changeTo);
- Console.WriteLine();
- Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement