Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int num = 0;
- string temp=" ";
- int[] ArrNum;
- do
- {
- do
- {
- int i;
- Console.WriteLine("Geben sie eine Binärzahl ein: \n\"5\" zum Beenden des Programms");
- try
- {
- num = Convert.ToInt32(Console.ReadLine());
- }
- catch
- {
- num = -2;
- }
- temp = num.ToString();
- for (i=2; i < 10; i++)
- {
- if (temp.Contains(i.ToString()))
- break;
- }
- }
- while (!(num >= 0)||i<10);
- if (num != 5)
- {
- ArrNum = new int[temp.Length];
- for (int i = 0; i < temp.Length; i++)
- {
- ArrNum[i] = Convert.ToInt32(temp.Substring(i, 1));
- }
- num = 0;
- for (int i = 0; i < temp.Length; i++)
- {
- if (ArrNum[i] == 1)
- num += Convert.ToInt32(Math.Pow(2, (temp.Length - i - 1)));
- }
- Console.WriteLine("Die Dezimalzahl hat den Wert " + num);
- }
- }
- while (num != 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement