- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Change_on_specific_possitions
- {
- class Program
- {
- static void Main(string[] args)
- {
- int position;
- int number;
- string strNum;
- string strPos;
- int i = 1;
- Console.WriteLine("Please enter initial number ");
- strNum = Console.ReadLine();
- Console.WriteLine("Please enter 1st position where you want to change ");
- strPos = Console.ReadLine();
- position = int.Parse(strPos);
- number = int.Parse(strNum);
- int positionChng;
- string strPosChng;
- int iChng = 1;
- Console.WriteLine("Please enter 1st position of the numbers you will change with ");
- strPosChng = Console.ReadLine();
- positionChng = int.Parse(strPosChng);
- Console.WriteLine("Please enter the number of exchanges ");
- string strNumofSwaps = Console.ReadLine();
- int numOfSwaps = int.Parse(strNumofSwaps);
- int counterNumSwaps = 1;
- int finalResult = number;
- int result;
- int resultChng;
- result = number;
- resultChng = number;
- while (counterNumSwaps <= numOfSwaps)
- {
- i = i << (position - 1);
- result = (result & i);
- int chngZeroOne;
- if (result > 0)
- chngZeroOne = 1;
- else
- chngZeroOne = 0;
- iChng = iChng << (positionChng - 1);
- resultChng = (resultChng & iChng);
- int chngZeroOneNew;
- if (resultChng > 0)
- chngZeroOneNew = 1;
- else
- chngZeroOneNew = 0;
- if (chngZeroOne != chngZeroOneNew)
- {
- finalResult = ((finalResult ^ i) ^ iChng);
- }
- i = 1;
- position++;
- result = number;
- iChng = 1;
- positionChng++;
- resultChng = number;
- counterNumSwaps++;
- Console.WriteLine("The result after the swap is {0}", finalResult);
- }
- Console.WriteLine("The result after the swaps is {0}", finalResult);
- }
- }
- }
SHARE
TWEET

Change Positions




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.