Skip to content

Instantly share code, notes, and snippets.

@esase
Created April 18, 2022 04:43
Show Gist options
  • Save esase/97df0faa00471baa7f0d29d69c60ec56 to your computer and use it in GitHub Desktop.
Save esase/97df0faa00471baa7f0d29d69c60ec56 to your computer and use it in GitHub Desktop.
var hammingWeight = function(n) {
let bitsCount = 0;
for (let i = 1; i <= 32; i++) {
if (n & 1) {
bitsCount++;
}
n = n >> 1;
}
return bitsCount;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment