Advertisement
stefan1919

Catch the Bits

Jul 20th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace novo2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int n;
  15.             n = int.Parse(Console.ReadLine());
  16.             int step;
  17.             step = int.Parse(Console.ReadLine());
  18.             string binary = "";
  19.             string b = "";
  20.             int f;
  21.             int newNumber;
  22.             string firstNumber = "";
  23.             string secondNumber = "";
  24.             for (int i = 0; i < (n); i++)
  25.             {
  26.                 f = 1 + (i * step);
  27.                 newNumber = int.Parse(Console.ReadLine());
  28.                 binary = binary + Convert.ToString(newNumber, 2).PadLeft(8, '0');
  29.             }
  30.             for (int i = 0; (1 + (i * step)) < (8 * n); i++)
  31.             {
  32.                
  33.                     f = 1 + (i * step);
  34.                     b += binary[f];
  35.                
  36.                
  37.             }
  38.             int count = b.Length;
  39.             for (int j = 0; j < count; j++)
  40.             {
  41.                 if (j < 8)
  42.                 {
  43.                     firstNumber = firstNumber + b[j];
  44.                 }
  45.                 else
  46.                 {
  47.                     secondNumber = secondNumber + b[j];
  48.                 }
  49.             }
  50.             int firstValue;
  51.             int secondValue;
  52.             firstNumber = firstNumber.PadRight((8), '0');
  53.             firstValue = Convert.ToInt32(firstNumber, 2);
  54.             secondNumber = secondNumber.PadRight((8), '0');
  55.             secondValue = Convert.ToInt32(secondNumber, 2);
  56.             Console.WriteLine(firstValue);
  57.             if (secondValue > 0)
  58.             {
  59.                 Console.WriteLine(secondValue);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement