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 ExtractBitFromInteger
- {
- class ExtractBitFromInteger
- {
- static void Main()
- {
- int num, p;
- Console.WriteLine("Enter number: ");
- num = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter position of bit: ");
- p = int.Parse(Console.ReadLine());
- int numRightP = num >> p;
- int bit = numRightP & 1;
- Console.WriteLine("The bit of number " + num + " which is in" + " position " + p + " is " + bit);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment