Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Last active June 28, 2018 14:11
Show Gist options
  • Save sreeprasad/db3426b20cc5161dfed25baf308f691e to your computer and use it in GitHub Desktop.
Save sreeprasad/db3426b20cc5161dfed25baf308f691e to your computer and use it in GitHub Desktop.
Find number of bits set with O(N) time where N is the total number of bits in the number
int findBitSet(int n){
int count=0;
while(n>0){
if(n&1 == 0) {
count++;
}
n=>>1;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment