Isolate the right most set bit of integer n
#include <iostream>
using namespace std;
//function to isolate rightmost set bit of integer n
unsigned isolateRightMostSetBit(unsigned int n)
{
int result = n & ~(n - 1);
return result;
}
int main()
{
unsigned int n = 10;
unsigned int result = isolateRightMostSetBit(n);
cout << "After isolating right most set bit of integer "<< n << ", we get "<< result<<"." << endl;
return 0;
}
Comments
Post a Comment