LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (June 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 25 Jun 2001 23:03:43 GMT
Reply-To:     Jens Manfredson <HFUOQUCSVTYY@SPAMMOTEL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jens Manfredson <HFUOQUCSVTYY@SPAMMOTEL.COM>
Subject:      Re: Count the '1's in a binary number?
Content-Type: text/plain; charset="iso-8859-1"

> 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.

Jens


Back to: Top of message | Previous page | Main SAS-L page