Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CatchTheBits
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- int[] bits = new int[n];
- for (int i = 0; i < n; i++)
- {
- bits[i] = int.Parse(Console.ReadLine());
- }
- int bytes = n * 8;
- string all = "";
- for (int i = 0; i < n; i++)
- {
- all += Convert.ToString(bits[i], 2).PadLeft(8, '0');
- }
- int stepPos = 1;
- string result = "";
- for (int i = 0; i < all.Length; i++)
- {
- result += all[stepPos];
- stepPos += step;
- if (stepPos > bytes)
- {
- break;
- }
- else if(stepPos == all.Length)
- {
- result += '0';
- break;
- }
- }
- int pad = 0;
- while(pad < result.Length)
- {
- pad += 8;
- }
- result = result.PadRight(pad, '0');
- if (result.Length > 8)
- {
- string num = "";
- int count = 1;
- for (int i = 0; i < result.Length; i++)
- {
- if (i < count * 8)
- {
- num += result[i];
- }
- if (num.Length == 8)
- {
- Console.WriteLine(Convert.ToInt64(num, 2));
- num = "";
- count++;
- }
- }
- }
- else
- {
- Console.WriteLine(Convert.ToInt32(result, 2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement