settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Bitwise C#: Extract Bit at position 3 (#3)

+4 votes

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

asked in C# category by user john7
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

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);
    }
}
answered by user paulcabalit
edited by user golearnweb
...