Answers for "Check whether K-th bit is set or not c++"

C++
0

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";
}
Posted by: Guest on April-18-2021
0

Check whether K-th bit is set or not c++

n & (1 << (k - 1))
(n >> (k - 1)) & 1
Posted by: Guest on April-18-2021

Code answers related to "Check whether K-th bit is set or not c++"

Browse Popular Code Answers by Language