Advertisement
Aggrodin

Problem 12: Extract Bit from Integer

Mar 18th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. namespace ExtractBitFromInteger
  3. {
  4.     class ExtractBitFromInteger
  5.     {
  6.         static void Main()
  7.         {
  8.             Console.Write("Enter the number : ");
  9.             int number = int.Parse(Console.ReadLine());
  10.             Console.Write("Enter the bit : ");
  11.             int bit = int.Parse(Console.ReadLine());
  12.             int move = number >> bit;
  13.             int result = move & 1;
  14.             Console.WriteLine("The bit on position {0} is {1}" , bit , result);
  15.         }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement