Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _5.CatchTheBits
- {
- using System;
- public class CatchTheBits
- {
- public static void Main(string[] args)
- {
- checked
- {
- int count = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- int bitCounter = 0;
- int positionInSequence = 0;
- int bitSequence = 0;
- for (int i = 0; i < count; i++)
- {
- byte numBytes = byte.Parse(Console.ReadLine());
- for (int currentBit = 7; currentBit >= 0; currentBit--)
- {
- if ((step == 1 && positionInSequence > 0) || (positionInSequence % step) == 1)
- {
- int bitMask = 1 << currentBit;
- int bitValue = (numBytes & bitMask) >> currentBit;
- bitSequence <<= 1;
- bitSequence |= (byte)bitValue;
- bitCounter++;
- if (bitCounter == 8)
- {
- Console.WriteLine(bitSequence);
- bitSequence = 0;
- bitCounter = 0;
- }
- }
- positionInSequence++;
- }
- }
- if (bitCounter > 0)
- {
- bitSequence <<= 8 - bitCounter;
- Console.WriteLine(bitSequence);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement