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

Q: Bitwise C#: Extract Bit from Integer

+6 votes

Write an expression that extracts from given integer n the value of given bit at index p.


extract bit from integer in C#

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

1 Answer

+2 votes
Best answer

Here's my solution:

using System;

class Bitwise
    static void Main()
        int number = int.Parse(Console.ReadLine());
        int position = int.Parse(Console.ReadLine());

        int numberRightposition = number >> position;
        int bit = numberRightposition & 1;

answered by user mitko
edited by user golearnweb