Check whether K-th bit is set or not c++ code example
Example 1: Check whether K-th bit is set or not c++
void isKthBitSet(int n, int k)
{
if (n & (1 << (k - 1)))
cout << "SET";
else
cout << "NOT SET";
}
Example 2: Check whether K-th bit is set or not c++
n & (1 << (k - 1))
(n >> (k - 1)) & 1