• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 25, 2023 |170 Views
SDE Sheet - Set kth bit
  Share   Like
Description
Discussion

This video is part of the Bit Manipulation section under the GFG SDE Sheet.

In this problem, we are given, a a number N and a value K. From the right, set the Kth bit in the binary representation of N. The position of Least Significant Bit(or last bit) is 0, the second last bit is 1 and so on.

Example :

Input:
N = 10 
K = 2
Output:
14

Explanation:
Binary representation of the given number10 is: 1 0 1 0, number of bits in the binary reprsentation is 4. Thus 2nd bitfrom right is 0. The number after changing this bit to 1 is: 14(1 1 1 0).

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/set-k-th-bit-given-number/
Problem: https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More