Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace BaseConverter
  9. {
  10.     class BaseConverter
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int convertnumber;
  15.             string val;
  16.             char ch ='y';
  17.  
  18.             Console.WriteLine("Menu \n\n1.Convert Decimal to Binary,Octal,Hexadecimal \n\n2.Convert Binary to Decimal,Octal,Hexadecimal \n\n3.Convert Octal to Decimal,Binary,Hexadecimal \n\n4.Convert Hexadecimal to Decimal,Binary,Octal");
  19.            
  20.             while (ch != 'n')
  21.             {
  22.                 int n = int.Parse(Console.ReadLine());
  23.                 switch (n)
  24.                 {
  25.                     case 1:
  26.  
  27.                         Console.WriteLine("\nEnter Decimal Number : ");
  28.                         String deci = Console.ReadLine();
  29.  
  30.                         //Decimal to binary
  31.                         convertnumber = Convert.ToInt32(deci, 10);
  32.                         Console.WriteLine("\nDecimal to Binary : " + Convert.ToString(convertnumber, 2));
  33.  
  34.                         //Decimal to octal
  35.                         convertnumber = Convert.ToInt32(deci, 10);
  36.                         Console.WriteLine("\nDecimal to Octal : " + Convert.ToString(convertnumber, 8));
  37.  
  38.                         //Decimal to Hexadecimal
  39.                         convertnumber = Convert.ToInt32(deci, 10);
  40.                         Console.WriteLine("\nDecimal to Hexadecimal : " + Convert.ToString(convertnumber, 16));
  41.  
  42.                         break;
  43.  
  44.                     case 2:
  45.  
  46.                         Console.WriteLine("\nEnter Binary Number : ");
  47.                         val = Console.ReadLine();
  48.  
  49.                         //Binary to Decimal
  50.                         convertnumber = Convert.ToInt32(val, 2);
  51.                         Console.WriteLine("\nBinary to Decimal : " + Convert.ToString(convertnumber, 10));
  52.  
  53.                         //Binary to Octal
  54.                         convertnumber = Convert.ToInt32(val, 2);
  55.                         Console.WriteLine("\nBinary to Octal : " + Convert.ToString(convertnumber, 8));
  56.  
  57.                         //Binary to Hexadecimal
  58.                         convertnumber = Convert.ToInt32(val, 2);
  59.                         Console.WriteLine("\nBinary to Hexadecimal : " + Convert.ToString(convertnumber, 16));
  60.  
  61.                         break;
  62.  
  63.  
  64.                     case 3:
  65.  
  66.                         Console.WriteLine("\nEnter Octal Number : ");
  67.                         String oct = Console.ReadLine();
  68.  
  69.                         //Octal to Decimal
  70.                         convertnumber = Convert.ToInt32(oct, 8);
  71.                         Console.WriteLine("\nOctal to Decimal : " + Convert.ToString(convertnumber, 10));
  72.  
  73.                         //Octal to Binary
  74.                         convertnumber = Convert.ToInt32(oct, 8);
  75.                         Console.WriteLine("\nOctal to Binary : " + Convert.ToString(convertnumber, 2));
  76.  
  77.                         //Octal to Hexadecimal
  78.                         convertnumber = Convert.ToInt32(oct, 8);
  79.                         Console.WriteLine("\nOctal to Hexadecimal : " + Convert.ToString(convertnumber, 16));
  80.  
  81.                         break;
  82.  
  83.                     case 4:
  84.  
  85.                         Console.WriteLine("\nEnter Hexadecimal Number : ");
  86.                         String hexa = Console.ReadLine();
  87.  
  88.                         //Hexadecimal to Decimal
  89.                         convertnumber = Convert.ToInt32(hexa, 16);
  90.                         Console.WriteLine("\nHexadecimal to Decimal : " + Convert.ToString(convertnumber, 10));
  91.  
  92.                         //Hexadecimal to Binary
  93.                         convertnumber = Convert.ToInt32(hexa, 16);
  94.                         Console.WriteLine("\nHexadecimal to Binary : " + Convert.ToString(convertnumber, 2));
  95.  
  96.                         //Hexadecimal to Octal
  97.                         convertnumber = Convert.ToInt32(hexa, 16);
  98.                         Console.WriteLine("\nHexadecimal to Octal : " + Convert.ToString(convertnumber, 8));
  99.  
  100.                         break;
  101.                 }
  102.  
  103.                 Console.WriteLine("\nDo you want to continue y or n");
  104.                 ch = char.Parse(Console.ReadLine());
  105.             }
  106.             Console.ReadKey();
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement