Advertisement
Kolimnared

BitKiller

Oct 17th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. class BitKiller
  4. {
  5. static void Main(string[] args)
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. int step = int.Parse(Console.ReadLine());
  9. byte[] nums = new byte[n];
  10.  
  11. for (int i = 0; i < n; i++)
  12. {
  13. nums[i] = byte.Parse(Console.ReadLine());
  14. }
  15.  
  16. int counter = 0;
  17. int num = 0;
  18. int bytesCounter = 0;
  19. for (int i = 0; i < n; i++)
  20. {
  21. for (int bytes = 7; bytes >= 0; bytes--, counter++) {
  22. if (!(counter > 0 && (counter % step == 1 || step == 1))) {
  23. ++bytesCounter;
  24. num <<= 1;
  25. num |= ((nums[i] >> bytes) & 1);
  26. if (bytesCounter == 8) {
  27. bytesCounter = 0;
  28. Console.WriteLine(num);
  29. num = 0;
  30. }
  31. }
  32. }
  33. }
  34. if (bytesCounter != 0) {
  35. num <<= (8 - bytesCounter);
  36. Console.WriteLine(num);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement