Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- namespace testing
- {
- class MainClass
- {
- public static void Main (string[] args)
- {
- byte one = 1 ;
- byte zero = 0 ;
- byte[] bits_array = { 1 , 1 , 1 , 1 } ;
- int k = 1 ;
- for ( int i = 1; i<=k ; i++ ) {
- // extracting least significant bit of last element of the array
- //byte last_bit = bits_array[bits_array.Length-1] & 1 ;
- // Setting the first
- byte setting_bit = 0 ;
- for ( int y = 0 ; y < bits_array.Length ; y++ ) {
- if ( y == bits_array.Length-1 ) {
- byte last_bit_to_be_circled = (bits_array[y] & one);
- if ( (setting_bit ^ (bits_array[y]>>7) )== one ) {
- if ( (bits_array[y]>>7) == zero) {
- bits_array[y] |= (setting_bit << 7);
- }
- else {
- bits_array[y] &= ~(one << 7);
- }
- }
- // Setting first element
- if ( (last_bit_to_be_circled ^ (bits_array[0]>>7) )== one ) {
- if ( (bits_array[0]>>7) == zero) {
- bits_array[y] |= (setting_bit << 7);
- }
- else {
- bits_array[1] &= ~(one << 7);
- }
- }
- }
- // extracting last bit of former element ( because i want it to set the next element of array )
- setting_bit = bits_array[y] & one ;
- // Shift it with one position
- //bits_array >>=1;
- // setting the first bit in later element ( by the extracted bit )
- // check if both bits are different ( if true then we must set it , else we do nothing
- if ( (setting_bit ^ (bits_array[y]>>7) )== 1 ) {
- if ( (bits_array[y]>>7) == 0) {
- bits_array[y] |= (setting_bit << 7);
- }
- else {
- bits_array[y] &= ~(1 << 7);
- }
- }
- }
- }
- foreach(byte test in bits_array ) {
- Console.WriteLine(test+" ");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment