Advertisement
stanevplamen

01.3.0а

Apr 28th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. using System;
  2.  
  3. class BasicOperators
  4. {
  5.     static void Main()
  6.     {
  7.         // How to get bit position - p from n
  8.         int p = 5; //position
  9.         int n = 35; // number
  10.         int mask = 1 << 5;
  11.         int nAndMask = n & mask;
  12.         Console.WriteLine(nAndMask);
  13.         int bit = nAndMask >> p;
  14.         Console.WriteLine(bit);
  15.         Console.WriteLine(Convert.ToString(bit, 2).PadLeft(32, '0'));
  16.  
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement