2進数表記の際に1bitsとなる位の数。
設問
Write a program to determine the number of 1 bits in the internal representation of a given integer.
Input sample:
The first argument will be a text file containing an integer, one per line. e.g.
10 22 56
Output sample:
Print to stdout, the number of ones in the binary form of each number.
e.g.
2 3 3
やってみた
#!/usr/bin/env ruby ARGF.lines do |line| puts line.to_i.to_s(2).count('1') end