svetlozar_kirkov

Bit At Position (Exercise)

Sep 27th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleTest
  5. {
  6.     class ConsoleTest
  7.     {
  8.         static void Main()
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             byte p = byte.Parse(Console.ReadLine());
  12.             int shifted = n>>p;
  13.             string num = Convert.ToString(shifted, 2);
  14.             char bitAtPosition = num.Last();
  15.             Console.WriteLine(bitAtPosition);
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment