Advertisement
Guest User

Untitled

a guest
Dec 14th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace BitBuilder
  9. {
  10.     class BitBuilder
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             long number = Convert.ToInt64(Console.ReadLine());
  15.            
  16.             string action = "";
  17.             int possition = 0;
  18.  
  19.  
  20.             long mask = 0;
  21.  
  22.             while (true)
  23.             {
  24.                 string possitionString = (Console.ReadLine());
  25.  
  26.                 if (possitionString == "quit")
  27.                 {
  28.                     Console.WriteLine(number);
  29.                     return;
  30.                 }
  31.                 else
  32.                 {
  33.                     possition = Convert.ToInt32(possitionString);
  34.                 }
  35.  
  36.                 action = Console.ReadLine();
  37.                 string maskAsString = new string('1', (int)possition);
  38.  
  39.                 if (possition != 0)
  40.                 {
  41.                     mask = Convert.ToInt64(maskAsString, 2);
  42.                 }
  43.                
  44.  
  45.                 if (action == "flip")
  46.                 {
  47.  
  48.                     number = number ^ (1 << possition);
  49.  
  50.                 }
  51.  
  52.                 long rightBits = (long)(number & mask);
  53.  
  54.                 if (action == "insert")
  55.                 {
  56.                    
  57.                     number = number >> possition;
  58.                     number = number << (possition + 1);
  59.                     number = number | ((long)1 << possition);
  60.                     number = number | rightBits;
  61.  
  62.                 }
  63.  
  64.                 if (action == "remove")
  65.                 {
  66.                     number = number >> (possition + 1);
  67.                     number = number << possition;
  68.                     number = (long)number | rightBits;
  69.  
  70.                 }
  71.  
  72.                 if (action == "skip")
  73.                 {
  74.                     continue;
  75.  
  76.                 }
  77.  
  78.  
  79.             }
  80.            
  81.         }
  82.  
  83.  
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement