Guest User

Bit Flipper

a guest
Dec 3rd, 2014
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. namespace BitFlipper
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             ulong n = ulong.Parse(Console.ReadLine());//594226797558350599;
  8.             ulong mask = 16140901064495857664;
  9.  
  10.             while (mask >= 7)
  11.             {
  12.                 if ((mask & n) == mask || (mask & n) == 0)
  13.                 {
  14.                     if ((mask & n) == mask)
  15.                     {
  16.                         n &= (~mask);
  17.                     }
  18.                     else
  19.                     {
  20.                         n |= mask;
  21.                     }
  22.                     mask >>= 3;
  23.                 }
  24.                 else
  25.                 {
  26.                     mask >>= 1;
  27.                 }
  28.             }
  29.             Console.WriteLine(n);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment