TheBulgarianWolf

Tri-Bit Switch

Jan 1st, 2021 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  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.  
Add Comment
Please, Sign In to add comment