mayap

CheckBitAtPositionP==1

Apr 11th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CheckBitAtGivenPosition
  8. {
  9.     class CheckBitAtGivenPosition
  10.     {
  11.         static void Main()
  12.         {
  13.             int num, p;
  14.             Console.WriteLine("Enter number: ");
  15.             num = int.Parse(Console.ReadLine());
  16.             Console.WriteLine("Enter position: ");
  17.             p = int.Parse(Console.ReadLine());
  18.  
  19.             int numRightP = num >> p;
  20.             int bit = numRightP & 1;
  21.  
  22.             if (bit == 1)
  23.             {
  24.                 Console.WriteLine(true);
  25.             }
  26.             else
  27.             {
  28.                 Console.WriteLine(false);
  29.             }
  30.  
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment