Baseline Bit Manipulation · Learn Bit Manipulation O(1) · O(1)
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.
0 <= n < 2^310 <= k <= 31Input: {"n":4,"k":0}
Output: false
4 is 100; the least significant pin carries no voltage.
Input: {"n":4,"k":2}
Output: true
The only set pin of 100 sits at index 2.