Finding B-th bit

I have a task to solve:
I must enter a positive integer N and 0 < B < 31 and print the B-th bit of number N (potential of digit 2B in binary number N).

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main(){
    int N, B;
    cout << "Insert N = ";
    cin >> N;
    
    do{
        cout << "Insert B = ";
        cin >> B;
    }
    while(B < 1 || B > 31);


And here I stoped. I have no idea what to do next.
Any ideas?
Last edited on
The result is

N >> B & 1

Only B shall be in the range 0 <= B <= 31.

Otherwise the above expression will look like

N >> B - 1 & 1
Last edited on
Topic archived. No new replies allowed.