dsa · easy
Check if Kth Bit is Set
GreyOrangeBit ManipulationFoundation
Return whether the k-th bit of n is set. k is **1-indexed from the right** (LSB is bit 1).
Arguments
n— the integer whose bits you inspectk— 1-indexed bit from the right (LSB is bit 1)
**Example:** n=5 (101), k=1 → true; k=2 → false.
Constraints
0 <= n <= 10^9, 1 <= k <= 31
Examples
Example 1
Input: 5 1 Expected: true
Example 2
Input: 5 2 Expected: false