G2A Many GEOs
SHARE
TWEET

Problem 11.Bitwise: Extract Bit #3

JOHNYTHEWINNER Apr 13th, 2015 272 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. public class ExtractBit
  4. {
  5.     public static void Main()
  6.     {
  7.         int p = 3;  //Here we set position of searched bit
  8.         Console.Write("Please input number: ");  //Here we ask for number
  9.         int number = int.Parse(Console.ReadLine());
  10.  
  11.         int mask = 1 << p;  //Here we set mask with value 1 at position P.
  12.         int foundBit = number & mask; //Here we check choosen bit. We use & to check is it 0 or 1.
  13.  
  14.         if (foundBit == 0) //Below we just print result
  15.         {
  16.             Console.WriteLine("Third bit is 0.");
  17.         }
  18.         else
  19.         {
  20.             Console.WriteLine("Third bit is 1.");
  21.         }
  22.     }
  23. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top