This is it!
I thought about using shift but forgot the mask, thanks
for reminding me. Here is the shift and mask algorithm:
64 data _null_;
67 do while(a>0);
69 put a= binary. cnt=;
Thank you very much!
> -----Original Message-----
> From: Jens Manfredson [mailto:HFUOQUCSVTYY@SPAMMOTEL.COM]
> Sent: Monday, June 25, 2001 4:04 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Count the '1's in a binary number?
> > Suppose I have a positive integer number and I want to
> count the number of
> > '1's in the number presented with a binary format, for
> example, 13 is
> > '1101' in binary, so the number of '1's = 3. I wonder if
> there is a way
> > I can count it without first converting to character string then use
> > compress() etc.? In other word, I need a pure mathematical
> algorithm, better
> > to be a one line solution.
> Normally you would do it with a shift operation and a mask operation.
> Shift 1 right, mask with 0000001 and add.