[Buffalo-pm] Re: [tpm] Bit Counting

Derek Wueppelmann dwueppel at newswire.ca
Wed Oct 1 14:14:12 CDT 2003


On Wed, 2003-10-01 at 14:40, Mike Stok wrote:
> On Wed, 1 Oct 2003, Quantum Mechanic wrote:
> 
> > I'm looking for an elegant way to generate a list of
> > numbers whose binary representation has a given number
> > of 1's. I also want to generate this list in numerical
> > order.
> > 
> > For example, with 4 bits on, less than 50:
> > 
> > 15 1111
> > 23 10111
> > 27 11011
> > 29 11101
> > 30 11110
> > 39 100111
> > 43 101011
> > 45 101101
> > 46 101110
> > 
> > Now it's easy enough to check every number up to the
> > limit, but it seems there should be a more efficient
> > method. On the other hand, the overhead involved in
> > "skipping" some numbers may be more expensive than the
> > straightforward approach. 
> > 
> > Anyone have any insights into this?

Sorry I didn't post directly to your post but here's a thought.

-- 
This e-mail transmission is intended for the addressee indicated 
above. It may contain information that is privileged, confidential or 
otherwise protected from disclosure. Any review, dissemination, or 
use of this transmission or its contents by persons other  than the
addressee is strictly prohibited.
---------------------------------------------------------------------
(0       Derek Wueppelmann             derek.wueppelmann at newswire.ca
 D--      Canada NewsWire Ltd.        http://www.newswire.ca 
/ )                     Work: (416) 863-2107
---------------------------------------------------------------------




More information about the Buffalo-pm mailing list