Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- Console.WriteLine("Enter a number whose bit at a current position you'd like to check.");
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine("Bit at which position you'd like to check?");
- int p = int.Parse(Console.ReadLine());
- int nRightP = n >> p;
- int bit = nRightP & 1;
- Console.WriteLine((bit == 1) ? "The bit at position {0} is {1}" : "The bit at position {0} is {1}", p, bit);
- }
Advertisement
Add Comment
Please, Sign In to add comment