Advertisement
Fundamentalen

BitwiseExtract

Mar 14th, 2014
1,679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. using System;
  2.  
  3. class BitwiseExtract
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter your number: ");
  8.         int number = int.Parse(Console.ReadLine());
  9.  
  10.         int fakeBit = 1 << 3;
  11.         int foundBit = number & fakeBit;
  12.  
  13.         if (foundBit == 0)
  14.         {
  15.             Console.WriteLine("Third bit is '0' " + Convert.ToString(number, 2).PadLeft(16, '0'));
  16.         }
  17.         else
  18.         {
  19.             Console.WriteLine("Third bit is '1' " + Convert.ToString(number, 2).PadLeft(16, '0'));
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement