Skip to content

Latest commit

 

History

History
13 lines (12 loc) · 455 Bytes

File metadata and controls

13 lines (12 loc) · 455 Bytes
int setBit(int N)
    {
        //If (N&(N+1))==0 means next number is 2 to the power. Hence this number has only 1's.
        //If it is !=0  in that case we can do the 'OR' operation on this number and one successor number.
        if((N & (N+1))==0)
            return N;
        int x=N+1;
        return x|N;
    }