News for hackers. Stuff that matters.
Re:Counting set bits in an interesting way by de_huit on Saturday April 30, 2022 @10:24AM (#31216289)
The version from Hacker's delight is fun and does not branch:

  int popcount32(unsigned i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = ((i + (i >> 4)) & 0x0F0F0F0F);
    return (i * 0x01010101) >> 24; 
  }

There are no comments on this comment yet.