Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Task05CatchTheBits
- {
- using System;
- using System.Collections.Generic;
- using System.Text;
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- StringBuilder bits = new StringBuilder();
- for (int i = 0; i < n; i++)
- {
- byte number = byte.Parse(Console.ReadLine());
- string bitNum = Convert.ToString(number, 2).PadLeft(8, '0');
- bits.Append(bitNum);
- }
- int nextStep = 1;
- int count = 1;
- StringBuilder result = new StringBuilder();
- while (nextStep < bits.Length)
- {
- result.Append(bits[nextStep]);
- nextStep = 1 + (count * step);
- count++;
- }
- int index = 0;
- List<byte> resultBits = new List<byte>();
- bool done = false;
- while (!done)
- {
- StringBuilder currNumBits = new StringBuilder();
- for (int i = 0; i < 8; i++)
- {
- try
- {
- currNumBits.Append(result[index + i]);
- }
- catch (Exception)
- {
- if (currNumBits.Length < 8)
- {
- if (currNumBits.Length != 0)
- {
- currNumBits.Append(new string('0', 8 - currNumBits.Length));
- }
- }
- done = true;
- break;
- }
- }
- if (currNumBits.Length != 0)
- {
- resultBits.Add(Convert.ToByte(currNumBits.ToString(), 2));
- }
- index += 8;
- }
- for (int i = 0; i < resultBits.Count; i++)
- {
- Console.WriteLine(resultBits[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement