elena1234

P-thBit

Oct 4th, 2020 (edited)
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PthBit
  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 = 1 << position;//after shift left with position value we have 1 value in mask at current position but another are 0
  15.             int result = (number & mask) >> position;//after shift right with position value we have 0 or 1 at last position but another are 0 using &
  16.             Console.WriteLine(result);
  17.         }
  18.     }
  19. }
  20.  
  21.  
  22.  
Add Comment
Please, Sign In to add comment