Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CheckBitAtGivenPosition
- {
- class CheckBitAtGivenPosition
- {
- static void Main()
- {
- int num, p;
- Console.WriteLine("Enter number: ");
- num = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter position: ");
- p = int.Parse(Console.ReadLine());
- int numRightP = num >> p;
- int bit = numRightP & 1;
- if (bit == 1)
- {
- Console.WriteLine(true);
- }
- else
- {
- Console.WriteLine(false);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment