Advertisement
kostovhg

CheckABitAtPosition

Jun 16th, 2016
163
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. class Program
  3.     {
  4.         static void Main(string[] args)
  5.         {
  6.             Console.Write("Enter whole number : ");
  7.             var v = int.Parse(Console.ReadLine());
  8.             Console.Write("Enter possition of the bit : ");
  9.             var p = int.Parse(Console.ReadLine());
  10.             var result = ((v >> p) % 2 == 1);
  11.             Console.WriteLine("The {0}-th bit = 1: {1}" , p, result);
  12.            
  13.             // lines for check
  14.             //Console.WriteLine("FEDCBA9876543210");
  15.             //Console.WriteLine(Convert.ToString(v , 2).PadLeft(16, '0'));
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement