Created
October 24, 2018 17:32
-
-
Save patelpreet422/f9127094984ea8dcde501f4563dad1bb to your computer and use it in GitHub Desktop.
Setting rightmost set bit of a number to zero.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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