Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CheckIfGivenBitHasValue1
- {
- static void Main()
- {
- /* Write a boolean expression that returns if the bit
- * at position p (counting from 0) in a given integer number v has value of 1.
- * Example: v=5; p=1 false.
- */
- Console.Write("v= ");
- int v = int.Parse(Console.ReadLine());
- Console.Write("p= ");
- int p = int.Parse(Console.ReadLine());
- Console.WriteLine();
- int mask = v >> p; // move p-bit at position 0
- bool checkValue = !(mask % 2 == 0);
- Console.WriteLine("Does the {1} bit of {0} have value of 1?\n---> {2}",v,p,checkValue);
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement