Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace bitbuilder
- {
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- string positionS = Console.ReadLine();
- string command = Console.ReadLine();
- while(command!="quit")
- {
- int result = 0;
- int position = int.Parse(positionS);
- if(command=="flip")
- {
- number = number ^ (1 << position);
- }
- if(command=="insert")
- {
- for (int i = 0; i <= 31; i++)
- {
- if (i == position)
- {
- result = result | (1 << position);
- i++;
- }
- int bit = (number >> i) & 1;
- result = result | bit << i;
- }
- number = result;
- }
- if(command =="remove")
- {
- for (int i = 0; i < 32; i++)
- {
- if (i == position)
- {
- continue;
- }
- result = result >> 1;
- int bit = (number >> i) & 1;
- result = result | bit << 30;
- }
- number = result;
- }
- positionS = Console.ReadLine();
- if (positionS == "quit")
- {
- break;
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(number);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement