摘要: long count_bits(long n) { unsigned int c; // c accumulates the total bits set in v for (c = 0; n; c++) n &= n - 1; // clear the least significant bit set return c;}http://gurmeetsingh.wordpress.co... 阅读全文
posted @ 2010-03-13 23:19 octoberfirst 阅读(170) 评论(0) 推荐(0) 编辑
摘要: The best method for counting bits in a 32-bit integer v is the following: http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel B[0] = 0x55555555 = 01010101 01010101 01010101 01010... 阅读全文
posted @ 2010-03-13 21:43 octoberfirst 阅读(313) 评论(0) 推荐(0) 编辑