Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // Write a Boolean expression that checks if the bit on position p in the
- //integer v has the value 1. Example v=5, p=1 -> false.
- class CheckBit
- {
- static void Main()
- {
- Console.Write("n = ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("p = ");
- int p = int.Parse(Console.ReadLine());
- int mask = (int)Math.Pow(2, p);
- string binaryMask = Convert.ToString(mask, 2); //binary of mask
- string binaryN = Convert.ToString(n, 2); //binary of n
- bool valueOne = true;
- int position = mask & n;
- if (position == 0)
- {
- valueOne = false;
- }
- Console.WriteLine(valueOne);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement