Search⌘ K

Check If Kth Bit Is Set/Unset

Understand how to check if the kth bit from the right in a number's binary representation is set or unset. This lesson guides you through using bitwise right shifts and AND operations to solve this problem in constant time. By mastering this technique, you'll improve your bit manipulation skills useful for coding interviews and efficient problem solving.

Introduction

In this question, input a number and check if the kthk^{th} bit is set or not.

Problem statement

Given two positive integers n and k check whether the bit at position k, from the right in the binary representation of n is set 1 ...