stkirov

10.BitPosition

Oct 4th, 2012
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _10.BitPosition
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.Write("Number: ");
  13.             int v = int.Parse(Console.ReadLine());
  14.             Console.Write("Position of the bit: ");
  15.             int p = int.Parse(Console.ReadLine());
  16.  
  17.             int mask = 1 << p;
  18.  
  19.             //Console.WriteLine("The {0} bit in {1} is {2}", p, v, (v&mask) != 0 ? 1 : 0);
  20.             Console.WriteLine((v&mask) != 0 ? true : false);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment