730. Check if the i-th bit is Set or Not

Given two integers n and i, return true if the ith bit in the binary representation of n (counting from the least significant bit, 0-indexed) is set (i.e., equal to 1). Otherwise, return false.

Example 1:

Input: n = 5, i = 0

Output: true

Explanation: Binary representation of 5 is 101. The 0-th bit from LSB is set (1).

Example 2:

Input: n = 10, i = 1

Output: true

Explanation: Binary representation of 10 is 1010. The 1-st bit from LSB is set (1).

Now Your Turn!

Pick the correct output for the given input

Input: n = 16, i = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 109
  • 0 <= i <= 31

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool checkIthBit(int n, int i) {
// Your code goes here
}
};
Test Case

Input:

I
N