Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace PthBit
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- int position = int.Parse(Console.ReadLine());
- int mask = 1 << position;//after shift left with position value we have 1 value in mask at current position but another are 0
- int result = (number & mask) >> position;//after shift right with position value we have 0 or 1 at last position but another are 0 using &
- Console.WriteLine(result);
- }
- }
- }
Add Comment
Please, Sign In to add comment