Skip to content

Instantly share code, notes, and snippets.

@potix2
Created September 17, 2011 13:29
Show Gist options
  • Save potix2/1223935 to your computer and use it in GitHub Desktop.
Save potix2/1223935 to your computer and use it in GitHub Desktop.
numofbits
int numofbits5(long bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment