stefan1919

ChangeBits

Aug 18th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 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 ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         //static bool theCenterOfTheCrossroad(int[] row, int[] column, int i, int j)
  12.         //{
  13.         //    bool b;
  14.         //    if (column.Contains(j))
  15.         //    {
  16.                
  17.         //    }
  18.         //}
  19.         static void Main(string[] args)
  20.         {
  21.             int n = int.Parse(Console.ReadLine());
  22.             int step = int.Parse(Console.ReadLine());
  23.             int counter = 0;
  24.             int added = 0;
  25.             string newnumber = string.Empty;
  26.             string bitwise = string.Empty;
  27.             List<string> input = new List<string>();
  28.             string output = string.Empty;
  29.             int checker = 0;
  30.             for (int i = 0; i < n; i++)
  31.             {
  32.                 int numberForChange = int.Parse(Console.ReadLine());
  33.                 bitwise = Convert.ToString(numberForChange, 2).PadLeft(8, '0');
  34.                 input.Add(bitwise);
  35.                 counter++;
  36.             }
  37.  
  38.             foreach (var item in input)
  39.             {
  40.                 newnumber += item;
  41.             }
  42.             int f = 0;
  43.             char[] array = newnumber.ToCharArray();
  44.             for (int j = 0; j < counter * 8; j++)
  45.             {
  46.                 if ( 1 + (j * step) < counter * 8)
  47.                 {
  48.                     f = (j * step);
  49.                 if (array[f] == '0')
  50.                 {
  51.                     array[f] = '1';
  52.                 }
  53.                 else
  54.                 {
  55.                     array[f] = '0';
  56.                 }
  57.                 }
  58.                 else
  59.                 {
  60.                     break;
  61.                 }
  62.                
  63.             }
  64.             Console.WriteLine(array);
  65.             int flushed = 1;
  66.  
  67.             for (int v = 0; v < counter * 8; v++)
  68.             {
  69.                 if (checker != 7)
  70.                 {
  71.                     output += array[v];
  72.                     checker++;
  73.                 }
  74.                
  75.                 else
  76.                 {
  77.                     output += array[v];
  78.                     Console.WriteLine(output);
  79.                     int p = Convert.ToInt32(output, 2);
  80.                     Console.WriteLine(p);
  81.                     output = string.Empty;
  82.                     flushed++;
  83.                     checker = 0;
  84.                 }
  85.                
  86.             }
  87.            
  88.  
  89.            
  90.                
  91.                
  92.                    
  93.            
  94.  
  95.  
  96.  
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment