Input: ‘N’ = 5, ‘K’ = 1
Output: YES
5 in binary can be written as 101 and as we can see a first bit from the right of 5 is set so the answer is 'YES'.
The first line contains two integers ‘N’ and ‘K’ respectively.
The only line contains 'YES', if the 'K-th' bit is set, else 'NO'.
You don't need to print anything. It has already been taken care of. Just implement the given function.
Bitwise and of two bits is true if both bits are high. Left shift operation shifts the bit left by a given number so left shift by K is like 2^K so what we can do is we can shift 1 to the left by k-1 which makes it 2^(K-1) and we do the bitwise and of this with number ‘N’ which result in 2^(K-1) if kth bit is set else it becomes 0. We are reducing K to K-1 because bits start from 0.
In the previous approach we shift 1 to left by (K-1) bits here we will shift N by (K-1) times to the right which will put the K-1 th bit at 0th position and we will check if it is set or not by checking either the number is odd or not.