Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is not arithmetic shift better in countSetBits.js? #1152

Open
@oThinas

Description

@oThinas

The filecountSetBits.js has the function:

/** *@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 linenumber >>>= 1 instead of a logical shift, thus preserving the sign of the number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp