Advertisement
Devilchild656

HomeWork3 Problem 12

Mar 21st, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _12.ExtractBitfromInteger
  8. {
  9.     class ExtractBit
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter number ");
  14.             int Number = int.Parse(Console.ReadLine());
  15.             Console.WriteLine("Enter P");
  16.             int p = int.Parse(Console.ReadLine());
  17.             string convert = Convert.ToString(Number, 2).PadLeft(16, '0');
  18.             Console.WriteLine("Number code in Bits = {0}", convert);
  19.             int Numberl = Convert.ToInt32(convert);
  20.             int mask = 1;
  21.             mask = mask << p;
  22.             int secondmask = Number & mask;
  23.  
  24.             if (secondmask != 0)
  25.             {
  26.  
  27.                 Console.WriteLine("Bit position is {0} is 1", p);
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine("Bit position is {0} is 0",p);
  32.             }
  33.  
  34.  
  35.  
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement