Skip to content

Instantly share code, notes, and snippets.

@gwa
Last active December 16, 2015 02:39
Show Gist options
  • Save gwa/5364271 to your computer and use it in GitHub Desktop.
Save gwa/5364271 to your computer and use it in GitHub Desktop.
Get the number of bits set in a binary number.
function getNumBitsSet(binary) {
var numbits = 0;
for (var v=binary; v; v>>=1) {
numbits += v&1;
}
return numbits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment