coasterka

#3ExtractCurrentBitFromInt

Mar 13th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             Console.WriteLine("Enter a number whose bit at a current position you'd like to check.");
  4.             int n = int.Parse(Console.ReadLine());
  5.             Console.WriteLine("Bit at which position you'd like to check?");
  6.             int p = int.Parse(Console.ReadLine());
  7.             int nRightP = n >> p;
  8.             int bit = nRightP & 1;
  9.             Console.WriteLine((bit == 1) ? "The bit at position {0} is {1}" : "The bit at position {0} is {1}", p, bit);
  10.         }
Advertisement
Add Comment
Please, Sign In to add comment