Advertisement
Jakobhorak28

Untitled

Sep 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void Main(string[] args)
  2.         {
  3.  
  4.             int num = 0;
  5.             string temp=" ";
  6.             int[] ArrNum;
  7.             do
  8.             {                
  9.                 do
  10.                 {
  11.                     int i;
  12.                     Console.WriteLine("Geben sie eine Binärzahl ein: \n\"5\" zum Beenden des Programms");
  13.                     try
  14.                     {
  15.                         num = Convert.ToInt32(Console.ReadLine());
  16.                     }
  17.                     catch
  18.                     {
  19.                         num = -2;
  20.                     }
  21.                     temp = num.ToString();
  22.                     for (i=2; i < 10; i++)
  23.                     {
  24.                         if (temp.Contains(i.ToString()))
  25.                             break;
  26.                     }
  27.  
  28.                 }
  29.                 while (!(num >= 0)||i<10);
  30.                 if (num != 5)
  31.                  {
  32.                
  33.                     ArrNum = new int[temp.Length];
  34.                
  35.  
  36.                     for (int i = 0; i < temp.Length; i++)
  37.                     {
  38.                         ArrNum[i] = Convert.ToInt32(temp.Substring(i, 1));
  39.                     }
  40.                     num = 0;
  41.                
  42.                     for (int i = 0; i < temp.Length; i++)
  43.                     {
  44.                         if (ArrNum[i] == 1)
  45.                             num += Convert.ToInt32(Math.Pow(2, (temp.Length - i - 1)));
  46.                     }
  47.                     Console.WriteLine("Die Dezimalzahl hat den Wert " + num);
  48.                 }
  49.             }
  50.             while (num != 5);
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement