Check If Kth Bit Is Set/Unset
In this lesson, we try to find a bit in the binary representation of a number at the kth position and check if it is set/un-set.
Introduction
In this question, input a number and check if the 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
or unset 0
.
Input: n = 5, k = 1
Output: true
Input: n = 10, k = 2
Output: true
Input: n = 10, k = 1
Output: false
Algorithm
...Access this course and 1400+ top-rated courses and projects.