Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Euclidean Algorithm #200

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improved the countSetBit
amitsingh19975 committed Sep 3, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit df8942f21e8130af42679886840718b0518dac04
8 changes: 4 additions & 4 deletions src/algorithms/math/bits/countSetBits.js
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ export default function countSetBits(originalNumber) {
let number = originalNumber;

while (number) {
// Add last bit of the number to the sum of set bits.
setBitsCount += number & 1;
// Using And operation on number with previous number.
number &= (number - 1);

// Shift number right by one bit to investigate other bits.
number >>= 1;
// Increamenting number by 1.
setBitsCount += 1;
}

return setBitsCount;