Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Created July 20, 2015 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdonchev/88882e511d2185a52b82 to your computer and use it in GitHub Desktop.
Save vdonchev/88882e511d2185a52b82 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
class CatchTheBits
{
static void Main()
{
int count = int.Parse(Console.ReadLine());
int step = int.Parse(Console.ReadLine());
string bitHolder = string.Empty;
int index = 0;
List<int> output = new List<int>();
for (int i = 0; i < count; i++)
{
int num = int.Parse(Console.ReadLine());
for (int bit = 7; bit >= 0; bit--)
{
if ((index % step == 1) || (step == 1 && index > 0))
{
bitHolder += num >> bit & 1;
if (bitHolder.Length >= 8)
{
output.Add(Convert.ToInt32(bitHolder, 2));
bitHolder = string.Empty;
}
}
index++;
}
}
if (bitHolder.Length > 0)
{
output.Add(Convert.ToInt32(bitHolder.PadRight(8, '0'), 2));
}
foreach (var nums in output)
{
Console.WriteLine(nums);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment