Advertisement
marin4ooo

05. Catch The Bits C# Basics Exam 11

Jul 29th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _17_Catch_the_Bits
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int step = int.Parse(Console.ReadLine());
  11.            
  12.  
  13.             int number = 0;
  14.             string all = null;
  15.             char[] seq=new char[n*8];
  16.             string bin = null;
  17.  
  18.            
  19.  
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 number = int.Parse(Console.ReadLine());
  23.                 string input = Convert.ToString(number, 2);
  24.                 string inputByte = input.PadLeft(8, '0');
  25.                 all = all + inputByte;
  26.             }
  27.  
  28.             for (int t = 0; t < n*8; t++)
  29.             {
  30.                 if (1 + t * step > n * 8)
  31.                 {
  32.                     continue;
  33.                 }
  34.                 seq[t] = all[1 + t * step];
  35.             }
  36.            
  37.             for (int l = 0; l < seq.Length; l++)
  38.             {
  39.                 if (seq[l]=='\0')
  40.                 {
  41.                     continue;
  42.                 }
  43.                 bin = bin + seq[l];
  44.             }
  45.  
  46.             int ctr =(int)System.Math.Ceiling((decimal)bin.Length/8);
  47.             string middle = bin.PadRight(ctr*8, '0');
  48.  
  49.             int p = 0;
  50.             while (p < ctr*8)
  51.             {
  52.                 string final = middle.Substring(p, 8);
  53.                 int end = Convert.ToInt32(final, 2);
  54.                 Console.WriteLine(end);
  55.                 p = p + 8;
  56.             }
  57.            
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement