Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BitKiller
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int size = int.Parse(Console.ReadLine());
  14.             int step = int.Parse(Console.ReadLine());
  15.             int[] bytes = new int[size];
  16.             int[] outputArray = new int[0];
  17.             int counter = 0;
  18.             int outputBits = 7;
  19.             int outputBytes = 0;
  20.             int bitValue = 0;
  21.             for (int row = 0; row < bytes.Length; row++)
  22.             {
  23.                 bytes[row] = int.Parse(Console.ReadLine());
  24.                 for (int col = 7; col >= 0; col--)
  25.                 {
  26.                     bitValue = bytes[row] >> col & 1;
  27.                     if ((counter % step == 1) || (counter != 0 && step == 1))
  28.                     {
  29.                         counter++;
  30.                         continue;
  31.                     }
  32.                     else if (outputBits > 0)
  33.                     {
  34.                         if (outputBits == 7)
  35.                         {
  36.                             Array.Resize(ref outputArray, outputArray.Length + 1);
  37.                         }
  38.                         outputArray[outputBytes] |= bitValue << outputBits;
  39.                         outputBits--;
  40.                     }
  41.                     else
  42.                     {
  43.                         outputArray[outputBytes] |= bitValue << outputBits;                        
  44.                         outputBytes++;
  45.                         outputBits = 7;
  46.                     }
  47.                     counter++;
  48.                 }
  49.  
  50.             }
  51.             for (int i = 0; i < outputArray.Length; i++)
  52.             {
  53.                 Console.WriteLine("{0}", outputArray[i]);
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement