1266. Check if Nth Bit is Set

EasyBit ManipulationBit ManipulationBit MaskingShift

Given an integer n and a 0-indexed bit position k, determine whether the k-th bit of n is set (equal to 1). Return true if that bit is 1, otherwise false.

Input: A JSON object {"n": <integer>, "k": <bit index>} with 0 <= k <= 40.

Output: Return true if bit k of n is 1, otherwise false.

Examples

Example 1
Input: {"n":5,"k":2}
Output: true
Explanation: 5 is 101; bit 2 is 1, so the answer is true.
Example 2
Input: {"n":5,"k":1}
Output: false
Explanation: 5 is 101; bit 1 is 0, so the answer is false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →