Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- Console.WriteLine("Enter a random number to check one of its bits of your choice.");
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine("The bit at which position would you like to check?");
- int p = int.Parse(Console.ReadLine());
- int nRightP = n >> p;
- int bit = nRightP & 1;
- bool bitIsOne = bit == 1;
- Console.WriteLine(Convert.ToString(n, 2).PadLeft(16, '0'));
- Console.WriteLine("Bit at position {0} is = 1 - {1}", p, bitIsOne);
- }
Advertisement
Add Comment
Please, Sign In to add comment