Create a program that computes the hamming weight of a string. Winner is the program with the lowest hamming weight.
Rules:
- Hamming weight for an ASCII character is defined as the total number of bits set to
1
in its binary representation. - Assume input encoding is 7-bit ASCII, passed through whatever input mechanism is normal for your language (e.g. stdin, args, etc.)
- Output the result, as a number, to stdout or whatever default/normal output mechanism your language uses.
- It should go without saying, but you have to be able to actually run the program, in real life, for it to be a valid solution.
- Winner is the solution whose code has the lowest hamming weight.
Sorry, no solutions in whitespace for this one!Ok, you can code in whitespace now I've sorted out the rules :)
Per-character examples:
char | binary | weight
-----+----------+-------
a | 01100001 | 3
x | 01111000 | 4
? | 00111111 | 6
\x00 | 00000000 | 0
\x7F | 01111111 | 7
0x20
/ASCII 32 as the reference, isn't the humming weight ofhello world
10 rather than 11? \$\endgroup\$hello world
11? Only 10 characters are different from a space. Also - a program's Hamming weight seems to be just its length, excluding spaces. Not so different from normal code golf. \$\endgroup\$~
ANDo
. \$\endgroup\$