Foibs

go from 8bit to number

Nov 26th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random rnd = new Random();
  10.             int num = rnd.Next(0, 1);
  11.             int[] arithmos = new int[8];
  12.             int pollap = 0;
  13.             int synolo = 0;
  14.             int iterator = 0;
  15.  
  16.             for (int i = 0; i < arithmos.Length; i++)
  17.             {
  18.                 arithmos[i] = rnd.Next(0, 2);
  19.                 Console.Write(arithmos[i]);
  20.             }
  21.  
  22.             for (int i=arithmos.Length-1; i>=0; i--)
  23.             {
  24.                 switch (iterator)
  25.                 {
  26.                     case 0:
  27.                         pollap = 1;
  28.                         break;
  29.  
  30.                     default: pollap = 2 * pollap;
  31.                         break;
  32.                 }
  33.  
  34.                 if (arithmos[i] == 1)
  35.                 {
  36.                     synolo += pollap;
  37.                     iterator++;
  38.                 }
  39.             }
  40.             Console.WriteLine("\n" + synolo);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment