Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace testing
  5. {
  6. class MainClass
  7. {
  8.  
  9.  
  10.  
  11.  
  12. public static void Main (string[] args)
  13. {
  14. byte one = 1 ;
  15. byte zero = 0 ;
  16.  
  17. byte[] bits_array = { 1 , 1 , 1 , 1 } ;
  18.  
  19. int k = 1 ;
  20.  
  21. for ( int i = 1; i<=k ; i++ ) {
  22.  
  23. // extracting least significant bit of last element of the array
  24. //byte last_bit = bits_array[bits_array.Length-1] & 1 ;
  25. // Setting the first
  26.  
  27. byte setting_bit = 0 ;
  28. for ( int y = 0 ; y < bits_array.Length ; y++ ) {
  29. if ( y == bits_array.Length-1 ) {
  30. byte last_bit_to_be_circled = (bits_array[y] & one);
  31. if ( (setting_bit ^ (bits_array[y]>>7) )== one ) {
  32. if ( (bits_array[y]>>7) == zero) {
  33. bits_array[y] |= (setting_bit << 7);
  34. }
  35.  
  36. else {
  37. bits_array[y] &= ~(one << 7);
  38. }
  39. }
  40.  
  41. // Setting first element
  42. if ( (last_bit_to_be_circled ^ (bits_array[0]>>7) )== one ) {
  43. if ( (bits_array[0]>>7) == zero) {
  44. bits_array[y] |= (setting_bit << 7);
  45. }
  46.  
  47. else {
  48. bits_array[1] &= ~(one << 7);
  49. }
  50. }
  51.  
  52.  
  53. }
  54.  
  55. // extracting last bit of former element ( because i want it to set the next element of array )
  56. setting_bit = bits_array[y] & one ;
  57. // Shift it with one position
  58. //bits_array >>=1;
  59.  
  60.  
  61. // setting the first bit in later element ( by the extracted bit )
  62. // check if both bits are different ( if true then we must set it , else we do nothing
  63. if ( (setting_bit ^ (bits_array[y]>>7) )== 1 ) {
  64. if ( (bits_array[y]>>7) == 0) {
  65. bits_array[y] |= (setting_bit << 7);
  66. }
  67.  
  68. else {
  69. bits_array[y] &= ~(1 << 7);
  70. }
  71. }
  72.  
  73.  
  74.  
  75. }
  76. }
  77.  
  78. foreach(byte test in bits_array ) {
  79. Console.WriteLine(test+" ");
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90. }
  91. }
Add Comment
Please, Sign In to add comment