Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

Program Discussion :: Bitwise Operator

Home > Programs > Bitwise Operator

14 / 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: