Guest User

Bit Flipper

a guest
May 3rd, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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.         UInt64 input = UInt64.Parse(Console.ReadLine());
  13.  
  14.         string represent = Convert.ToString((long)input, 2).PadLeft(64, '0');
  15.         //Console.WriteLine(represent);
  16.         char[] representation_array = represent.ToCharArray();
  17.  
  18.         for (int i = 0; i < representation_array.Length - 2; i++)
  19.         {
  20.             if (representation_array[i] == representation_array[i + 1] && representation_array[i + 1] == representation_array[i + 2])
  21.             {
  22.                 if (representation_array[i] == '1')
  23.                 {
  24.                     representation_array[i] = '0';
  25.                     representation_array[i + 1] = '0';
  26.                     representation_array[i + 2] = '0';
  27.                 }
  28.                 else if (representation_array[i] == '0')
  29.                 {
  30.                     representation_array[i] = '1';
  31.                     representation_array[i + 1] = '1';
  32.                     representation_array[i + 2] = '1';
  33.                 }
  34.                 i += 2;
  35.             }
  36.         }
  37.         string temp_repres = new string(representation_array);
  38.         int lenth = temp_repres.Length;
  39.  
  40.         UInt64 result = Convert.ToUInt64(temp_repres, 2);
  41.         Console.WriteLine(result);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment