• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 04, 2022 |2.3K Views
Check whether the bit at given position is set or unset
  Share  1 Like
Description
Discussion

Given two positive integers n and k. The problem is to check whether the bit at position k from the right in the binary representation of n is set (‘1’) or unset (‘0’). 
Constraints: 1 <= k <= number of bits in the binary representation of n.
Examples: 
 

Input : n = 10, k = 2
Output : Set
(10)10 = (1010)2
The 2nd bit from the right is set.

Input : n = 21, k = 4
Output : Unset


Check whether the bit at given position is set or unset : https://www.geeksforgeeks.org/check-whether-bit-given-position-set-unset/

Read More