Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write an expression that extracts from given integer n the value of given bit at index p.
- class ExtractBitFromInt
- {
- static void Main()
- {
- Console.Write("Enter a number: ");
- int number = int.Parse(Console.ReadLine());
- Console.Write("Enter a position: ");
- int position = int.Parse(Console.ReadLine());
- int mask = 1 << position;
- if ((mask & number) == 0)
- {
- Console.WriteLine("0");
- }
- else
- {
- Console.WriteLine("1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement