8000 bpo-29882: Add an efficient popcount method for integers by niklasf · Pull Request #771 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-29882: Add an efficient popcount method for integers #771

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

Merged
merged 13 commits into from
May 29, 2020
Merged
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
Prev Previous commit
Next Next commit
Doc: use positive example, mention population count
  • Loading branch information
mdickinson committed May 27, 2020
commit b87f1621aea6152743be0aff4fb68bcb707b7932
9 changes: 6 additions & 3 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,16 @@ class`. In addition, it provides a few more methods:
.. method:: int.bit_count()

Return the number of ones in the binary representation of the absolute
value of the integer::
value of the integer. This is also known as the population count.
Example::

>>> n = -19
>>> n = 19
>>> bin(n)
'-0b10011'
'0b10011'
>>> n.bit_count()
3
>>> (-n).bit_count()
3

Equivalent to::

Expand Down
0