Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Hamming weight
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Number of nonzero symbols in a string}} {{redirect|popcnt|The CPU instruction|SSE4#POPCNT_and_LZCNT}} {{Use dmy dates|date=May 2019|cs1-dates=y}} The '''Hamming weight''' of a [[string (computer science)|string]] is the number of symbols that are different from the zero-symbol of the [[alphabet]] used. It is thus equivalent to the [[Hamming distance]] from the all-zero string of the same length. For the most typical case, a given set of [[bit]]s, this is the number of bits set to 1, or the [[digit sum]] of the [[Binary numeral system|binary representation]] of a given number and the [[Taxicab geometry|''ℓ''₁ norm]] of a bit vector. In this binary case, it is also called the '''population count''',<ref name="Warren_2013"/> '''popcount''', '''sideways sum''',<ref name="Knuth_2009"/> or '''bit summation'''.<ref name="HP-16C_1982"/> {|class="wikitable" align="right" |+Examples !String !Hamming weight |- |'''111'''0'''1''' |4 |- |'''111'''0'''1'''000 |4 |- |00000000 |0 |- |'''678'''0'''1234'''0'''567''' |10 |} [[File:Hamming weight plot.png|thumb|right|A plot of Hamming weight for numbers 0 to 256.<ref name="formulae">{{cite web |url=https://formulae.org/?script=examples/Population_count |title=Population count the Fōrmulæ programming language |first=Laurence |last = R.Ugalde |website=Fōrmulæ |access-date=June 2, 2024}}</ref>]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)