Advertisement
Guest User

CatchTheBits

a guest
Jun 3rd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. public class CatchTheBits
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int bits = int.Parse(Console.ReadLine());
  8.         int step = int.Parse(Console.ReadLine());
  9.  
  10.         string output = String.Empty;
  11.         string array = String.Empty;
  12.  
  13.         for (int i = 0; i < bits; i++)
  14.         {
  15.             var digit = int.Parse(Console.ReadLine());
  16.             array += Convert.ToString(digit, 2).PadLeft(8, '0');
  17.         }
  18.  
  19.         for (int i = 1; i < array.Length; i += step)
  20.         {
  21.             output += array[i];
  22.             if (output.Length >= 8)
  23.             {
  24.                 Console.WriteLine(Convert.ToInt32(output, 2));
  25.                 output = String.Empty;
  26.             }
  27.         }
  28.  
  29.         if (output.Length > 0)
  30.         {
  31.             while (output.Length != 8)
  32.             {
  33.                 output += 0;
  34.             }
  35.             Console.WriteLine(Convert.ToInt32(output, 2));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement