Skip to content

Instantly share code, notes, and snippets.

@e-mihaylin
Last active July 17, 2018 11:43
Show Gist options
  • Save e-mihaylin/0198d52cd92d64bae344345368d8b151 to your computer and use it in GitHub Desktop.
Save e-mihaylin/0198d52cd92d64bae344345368d8b151 to your computer and use it in GitHub Desktop.
const hammingWeight = v => {
v = v - (v>>1 & 0x55555555);
v = (v & 0x33333333) + (v>>2 & 0x33333333);
return ((v + (v>>4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment