← DiffPush

Check for the ith bit

Baseline Bit Manipulation · Learn Bit Manipulation O(1) · O(1)

Probing One Pin of the Badge Register

A security badge encodes its zones as an integer, and the gate reader must ask whether one specific pin — counted from the least significant pin starting at zero — is currently carrying voltage. Shifting the register right by the pin's index parks that pin in the last slot, where a single AND with one reveals its state.

Input: An integer n and a 0-based bit index k.

Output: true when the k-th bit of n is set, false otherwise.

Constraints

Examples

Example 1

Input: {"n":4,"k":0}
Output: false
4 is 100; the least significant pin carries no voltage.

Example 2

Input: {"n":4,"k":2}
Output: true
The only set pin of 100 sits at index 2.

Solve this in your browser →

Also on LeetCode ↗