check if kth bit is set or not code

Solutions on MaxInterview for check if kth bit is set or not code by the best coders in the world

showing results for - "check if kth bit is set or not code"
Leticia
14 Oct 2018
1#include <iostream>
2using namespace std;
3
4//! Using LeftShift Operator
5
6void kthBit(int n, int k)
7{
8    if (n & (1 << k - 1) != 0)
9    {
10        cout << "Yes" << endl;
11    }
12    else
13    {
14        cout << "No" << endl;
15    }
16}
17
18int main()
19{
20    int n, k;
21    cin >> n >> k;
22    kthBit(n, k);
23    return 0;
24}