[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Bitwise Operator

Home > Programs > Bitwise Operator

344 / 15

Write an efficient program to set the rightmost unset bit.

Answer:

#include 

int main()
{
int z = 21;
setUnsitBit(z);
}

void setUnsitBit(int y)
{
int p=y,x = 0;

if (y == 0)
return;
if ((y&(y+1)) == 0)
return;

while (p > 0)
{
if (((y>>x) & 1) == 0)
break;
x++;
p = p/2;
}
printf("%d",(y |=1

Asked In ::

Post Your Answer Here:

Language:

Post Your Reply Here: