You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is not arithmetic shift better in countSetBits.js? #1152
/** * @param {number} originalNumber * @return {number} */exportdefaultfunctioncountSetBits(originalNumber){letsetBitsCount=0;letnumber=originalNumber;while(number){// Add last bit of the number to the sum of set bits.setBitsCount+=number&1;// Shift number right by one bit to investigate other bits.number>>>=1;}returnsetBitsCount;}
I wonder if it wouldn't be better to use an arithmetic shift on line number >>>= 1 instead of a logical shift, thus preserving the sign of the number.
Activity
Fix issue trekhleb#1152