Advertisement
Guest User

Untitled

a guest
Jun 27th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. int step = int.Parse(Console.ReadLine());
  9. int[] bitArray = new int[n];
  10. int result = 0;
  11. int count = 1;
  12. int bitCount = 0;
  13.  
  14. for (int i = 0; i < n; i++)
  15. {
  16. bitArray[i] = int.Parse(Console.ReadLine());
  17. }
  18. for (int i = 0; i < n; i++)
  19. {
  20. for (int j = 0; j < 8; j++)
  21. {
  22. if (count == 0)
  23. {
  24. int bitOnStep = (bitArray[i] >> 7-j) & 1;
  25. result = (result << 1) | bitOnStep;
  26. count = step;
  27. bitCount++;
  28. if (bitCount == 8)
  29. {
  30. Console.WriteLine(result);
  31. result = 0;
  32. bitCount = 0;
  33. }
  34. }
  35. count--;
  36. }
  37. }
  38. if (bitCount > 0)
  39. {
  40. result = (result << (8 - bitCount));
  41. Console.WriteLine(result);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement