Advertisement
Guest User

Untitled

a guest
Oct 15th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. class BitBuilder
  4. {
  5.     static void Main()
  6.     {
  7.         int number = int.Parse(Console.ReadLine());
  8.         long result = number;
  9.         while (true)
  10.         {
  11.             string p = Console.ReadLine();
  12.             int position;
  13.             if (p != "quit")
  14.             {
  15.                 position = int.Parse(p);
  16.             }
  17.             else
  18.             {
  19.                 break;
  20.             }
  21.             string command = Console.ReadLine();
  22.             if (command == "flip")
  23.             {
  24.                 result = (1 << position) ^ result;
  25.             }
  26.             else if (command == "remove")
  27.             {
  28.                 long leftHalf = result >> position + 1;
  29.                 leftHalf = leftHalf << position;
  30.                 long rightHalf = result << 32 - position;
  31.                 rightHalf = rightHalf & 4294967295;
  32.                 rightHalf = rightHalf >> 32 - position;
  33.                 result = rightHalf | leftHalf;
  34.             }
  35.             else if (command == "insert")
  36.             {
  37.                 long leftHalf = result >> position;
  38.                 leftHalf = leftHalf << position + 1;
  39.                 long rightHalf = result << 32 - position;
  40.                 rightHalf = rightHalf & 4294967295;
  41.                 rightHalf = rightHalf >> 32 - position;
  42.                 long combin = rightHalf | leftHalf;
  43.                 long mask = (long)1 << position;
  44.                 result = combin | mask;
  45.             }
  46.         }
  47.         Console.WriteLine(result);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement