Clear right most set bit of an integer n
#include <iostream>
using namespace std;
//function to clear rightmost set bit of integer n
unsigned clearRightMostSetBit(unsigned int n)
{
int result = n & (n - 1);
return result;
}
int main()
{
unsigned int n = 8;
unsigned int result = clearRightMostSetBit(n);
cout << "After clearing right most set bit of integer "<< n << ", we get "<< result<<"." << endl;
return 0;
}
Comments
Post a Comment