Skip to content

Instantly share code, notes, and snippets.

@patelpreet422
Created October 24, 2018 17:32
Show Gist options
  • Save patelpreet422/f9127094984ea8dcde501f4563dad1bb to your computer and use it in GitHub Desktop.
Save patelpreet422/f9127094984ea8dcde501f4563dad1bb to your computer and use it in GitHub Desktop.
Setting rightmost set bit of a number to zero.
#include <iostream>
#include <cstdio>
using namespace std;
unsigned long set_rightmost_bit_off(unsigned long k)
{
return k&(k-1);
}
int main()
{
cout << set_rightmost_bit_off(6ul) << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment