[Ratkaistu] Bitwise C#: Extract Bit at position 3 (#3)

  

3
Aiheen aloittaja

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.

Examples:

bitwise task c sharp

1 Vastaus
2

My solution is:

using System;
 
class BitwiseOperations
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int p = 3;
 
        int nRightp = n >> p;
        int bit = nRightp & 1;
 
        Console.WriteLine(bit);
    }
}
Jaa: