Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Count number of 1's in binary representation
  2. bitcount(n):
  3.     count = 0
  4.     while n > 0:
  5.         count = count + 1
  6.         n = n & (n-1)
  7.     return count
  8.        
  9. int BitCount(unsigned int u)
  10. {
  11.      unsigned int uCount;
  12.  
  13.      uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
  14.      return ((uCount + (uCount >> 3)) & 030707070707) % 63;
  15. }