Check if i-th Bit is Set
Learn Bit Manipulation DSA practice problem on Onlearn.
Difficulty: easy.
Topics: How to check if the i-th bit of an integer is set or not, Bitwise Operations, Input/Output Operations, Data Types, Conditional Statements, bit manipulation, binary representation, Bit Manipulation.
Given an integer N and an integer i, determine if the i th bit of N is set (i.e., is 1) or not (i.e., is 0). The bits are 0 indexed from the rightmost bit. Input The first line contains an integer N. The second line contains an integer i. Output Print "SET" if the i th bit is 1, and "NOT SET" if the i th bit is 0. Constraints 0 <= N <= 10^9 0 <= i <= 30 Sample Test Cases Sample Input 1 10 1 Sample Output 1 SET Explanation 1 Binary representation of 10 is 1010. The 1st bit (0 indexed from right) is 1. Sample Input 2 10 2 Sample Output 2 NOT SET Explanation 2 Binary representation of 10 is 1010. The 2nd bit (0 indexed from right) is 0.