hmmm...8 bit shift register and a BCD counter....still discrete logic but not a ton of gates. Makes me wonder why anyone would do it in gates....8 pin PIC, serial data in, BCD out? "Carlos A. Marcano V." wrote: Nice link, Adam. Thanks. I was looking for something less code-like and more hardware-like (TTL gates and similar) but it is a very interesting reading. Regards, *Carlos Marcano* -Guri, Venezuela- M. Adam Davis wrote: > From > http://my.opera.com/allbits/blog/show.dml/114980 > which has a whole slew of interesting operations. > > It's a start. > > ---------- > 13. Population Count (Ones Count) > > The population count of a binary integer value x is the number of one > bits in the value. Although many machines have single instructions for > this, the single instructions are usually microcoded loops that test a > bit per cycle; a log-time algorithm coded in C is often faster. The > following code uses a variable-precision SWAR algorithm to perform a > tree reduction adding the bits in a 32-bit value: > > unsigned int > ones32(register unsigned int x) > { > /* 32-bit recursive reduction using SWAR... > but first step is mapping 2-bit values > into sum of 2 1-bit values in sneaky way > */ > x -= ((x >> 1) & 0x55555555); > x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); > x = (((x >> 4) + x) & 0x0f0f0f0f); > x += (x >> 8); > x += (x >> 16); > return(x & 0x0000003f); > } > > ---------- > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --------------------------------- We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist