Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ex1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // get the bit at position (p) in number (n)
- int p = 3;
- int n = 42; //00101010
- int shifted = (n >> p); //00000101
- int result = shifted & 1; //00000001
- Console.WriteLine(result); //1
- // съкратен вариант
- //int result = ((n >> p) & 1);
- //Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment