TheBulgarianWolf

Tri-Bit Switch

Jan 1st, 2021 (edited)
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Tri_Bit_Switch
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your number here: ");
  11.             int number = int.Parse(Console.ReadLine());
  12.             Console.WriteLine("Enter the position of the first out of 3 bits you want to invert: ");
  13.             int firstPos = int.Parse(Console.ReadLine());
  14.             int helpNum = 7 << firstPos;
  15.             int invertedNumber = number^helpNum;
  16.             Console.WriteLine(invertedNumber);
  17.         }
  18.     }
  19. }
  20.  
RAW Paste Data