Skip to content

Instantly share code, notes, and snippets.

@iburlakov
Created November 25, 2015 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iburlakov/621cfae521ee2aaaeca9 to your computer and use it in GitHub Desktop.
Save iburlakov/621cfae521ee2aaaeca9 to your computer and use it in GitHub Desktop.
Calculate amount of 1 digits in given number
// calculate amount of 1 digits in given number
function calc(num) {
var digits = 0;
do {
if (num & 1) {
digits++;
}
num = num >>> 1
} while (num != 0);
return digits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment