Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write an expression that extracts from a given integer i the value of a given bit number b. Example: i=5; b=2 value=1.
- using System;
- class Program
- {
- static void Main()
- {
- int i = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- int mask = 1 << b;
- Console.WriteLine((i&mask)!=0 ? 1 : 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment