[해결로 표시] Bitwise C#: Extract Bit at position 3 (#3)

  

3
주제 스타터

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개 답글
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);
    }
}
공유: