Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a Boolean expression that returns if the bit at position p (counting from 0, starting from the right) in given //integer number n has value of 1.
- class CheckABitAtGivenPosition
- {
- static void Main()
- {
- Console.Write("Enter a number: ");
- int number = int.Parse(Console.ReadLine());
- Console.Write("Enter a position: ");
- int position = int.Parse(Console.ReadLine());
- int mask = 1 << position;
- bool isOne = ((mask & number) == 0 ? false : true);
- Console.WriteLine(isOne);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement