Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*
- * Using bitwise operators, write an expression for finding the value of the bit #3 of a given unsigned integer.
- * The bits are counted from right to left, starting from bit #0. The result of the expression should be either 1 or 0
- */
- class ExtractBit
- {
- static void Main()
- {
- byte n = 8; // In binary = 1000 - The third bit is 1
- Console.Write("Please enter the number: ");
- int number = int.Parse(Console.ReadLine());
- Console.Clear();
- Console.WriteLine("The entered number {0} in binary = {1}",number,Convert.ToString(number,2));
- bool thirdBit = (number & n) != 0;
- Console.WriteLine("Is the third bit 1: {0}",thirdBit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement