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 ExtractBit3
- {
- static void Main()
- {
- Console.Write("Enter a positive number: ");
- uint n = uint.Parse(Console.ReadLine());
- uint mask = 1 << 3;
- if ((n & mask) == 0)
- {
- Console.WriteLine("0");
- }
- else
- {
- Console.WriteLine("1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement