Population count

You are encouraged to solve this task according to the task description, using any language you may know.
The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer.

Population count   is also known as:

   pop count
   popcount 
   sideways sum
   bit summation 
   Hamming weight 


For example,   5   (which is   101   in binary)   has a population count of   2.


Evil numbers   are non-negative integers that have an   even   population count.

Odious numbers     are  positive integers that have an    odd   population count.



Task

 write a function (or routine) to return the population count of a non-negative integer.
 all computation of the lists below should start with   0   (zero indexed).
 display the   pop count   of the   1st   thirty powers of   3       (30,   31,   32,   33,   34,   ∙∙∙   329).
 display the   1st   thirty     evil     numbers.
 display the   1st   thirty   odious   numbers.
 display each list of integers on one line   (which may or may not include a title),   each set of integers being shown should be properly identified.


See also
 The On-Line Encyclopedia of Integer Sequences:   A000120 population count.
 The On-Line Encyclopedia of Integer Sequences:   A000069 odious numbers.
 The On-Line Encyclopedia of Integer Sequences:   A001969 evil numbers.


/*REXX program counts the number of "one" bits in the binary version of a decimal number*/
/*─────────────────── and also generates a specific number of  EVIL and ODIOUS  numbers.*/
parse arg N B .                                  /*get optional arguments from the C.L. */
if N==''  |  N==","   then N= 30                 /*N not specified?   Then use default. */
if B==''  |  B==","   then B=  3                 /*B  "      "          "   "      "    */
numeric digits 2000                              /*be able to handle  gihugeic  numbers.*/
numeric digits max(20, length(B**N) )            /*whittle the  precision  down to size.*/
$=                                               /* [↑]  a little calculation for sizing*/
     do j=0  for  N;   $= $ popCount(B**j)       /*generate N popCounts for some powers.*/
     end   /*j*/                                 /* [↑]  append popCount to the $ list. */
                                                 /* [↓]  display popCounts of "3" powers*/
call showList  'popCounts of the powers of'  B   /*display the list with a header/title.*/
 
     do j=0  until  #>=N                         /*generate   N   evil  numbers.        */
     if popCount(j) // 2  then iterate           /*if  odd population count, skip it.   */
     #= # + 1;      $= $ j                       /*bump evil # count;  add it to $ list.*/
     end   /*j*/                                 /* [↑]  build a list of evil numbers.  */
                                                 /* [↓]  display the evil number list.  */
call showList  'evil numbers'                    /*display the  $  list with a header.  */
 
     do j=0  until  #>=N                         /*generate   N   odious  numbers.      */
     if popCount(j) // 2 ==0  then iterate       /*if even population count, then skip. */
     #= # + 1;      $=$ j                        /*bump odious # count;  add to $ list. */
     end   /*j*/                                 /* [↑]  build a list of odious numbers.*/
                                                 /* [↓]  display the odious number list.*/
call showList  'odious numbers'                  /*display the   $  list with a header. */
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
d2b:      return word( strip( x2b( d2x( arg(1) ) ), 'L', 0)  0, 1)        /*dec ──► bin.*/
popCount: return length( space( translate( d2b(arg(1) ), , 0), 0) )       /*count ones. */
showList: say;   say 'The 1st'   N   arg(1)":";   say strip($);     #= 0;     $=;   return