Advertisement
coasterka

#3ExtractTheThirdBit

Mar 13th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.37 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             int p = 3;
  4.             Console.WriteLine("Enter a random number to extract the third bit from its binary conversion.");
  5.             int n = int.Parse(Console.ReadLine());
  6.             int nRightP = n >> p;
  7.             int bit = nRightP & 1;
  8.             Console.WriteLine("The third bit of the number {0} is {1}.", n, bit);
  9.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement