Posts Set kth bit (geeksforgeeks - SDE Sheet)
Post
Cancel

Set kth bit (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION

Given 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.

geeksforgeeks

SOLUTION

1
2
3
4
5
6
class Solution{
    static int setKthBit(int N,int K){
        // code here
        return (N | (1 << K));
    }
}
This post is licensed under CC BY 4.0 by the author.