elena1234

Tri-bitSwitch

Oct 4th, 2020 (edited)
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TriBitSwitch
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int number = int.Parse(Console.ReadLine());
  12.             int position = int.Parse(Console.ReadLine());
  13.  
  14.             int mask = 7 << position;// we need 111 at current position and int 7 = 111
  15.             int result = number ^ mask;//1 ^ 1 = 0, 0 ^ 1 = 1
  16.             Console.WriteLine(result);
  17.         }
  18.     }
  19. }
  20.  
  21.  
  22.  
Add Comment
Please, Sign In to add comment