Advertisement
Guest User

Catch The Bits

a guest
Apr 15th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13. int step = int.Parse(Console.ReadLine());
  14. int[,] input = new int[n, 8];
  15. int countOfBits = (n * 8 - 1) / step + 1;
  16. if(countOfBits % 8 != 0)
  17. countOfBits += 8 - countOfBits % 8;
  18. int[] output = new int[countOfBits];
  19. int[] preoutput = new int[n * 8];
  20.  
  21. for (int i = 0; i < n; i++)
  22. {
  23. int number = int.Parse(Console.ReadLine());
  24.  
  25. for (int j = 0; j < 8; j++)
  26. {
  27. if (number % 2 == 0)
  28. {
  29. input[i, j] = 0;
  30. }
  31. else
  32. input[i, j] = 1;
  33. number /= 2;
  34. }
  35.  
  36. }
  37.  
  38.  
  39. for (int i = 0, index = 0; i < n; i++)
  40. {
  41. for (int j = 7; j >= 0; j--, index++)
  42. {
  43. preoutput[index] = input[i, j];
  44. }
  45. }
  46.  
  47.  
  48.  
  49. for (int i = countOfBits - 1, j = 1; i >=0 ; i--)
  50. {
  51. if (j < preoutput.Length)
  52. {
  53. output[i] = preoutput[j];
  54. j += step;
  55. }
  56. else
  57. output[i] = 0;
  58. }
  59.  
  60. for (int i = output.Length / 8 - 1 ; i >=0 ; i--)
  61. {
  62. int result = 0;
  63. for (int j = 0 + i * 8; j < 8 + (i * 8); j++)
  64. {
  65. if (output[j] == 1)
  66. result += (int)Math.Pow(2, j - i * 8);
  67. }
  68.  
  69. Console.WriteLine(result);
  70. }
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement