1234567891011121314151617181920212223242526272829303132 |
- int oldbitcount(unsigned x);
- int newbitcount(unsigned x);
- int main()
- {
-
- return 0;
- }
- /* bitcount: count 1 bits in x */
- int oldbitcount(unsigned x)
- {
- int b;
- for (b = 0; x != 0; x >>= 1)
- if (x & 01)
- b++;
- return b;
- }
- /* bitcount: count 1 bits in x */
- int newbitcount(unsigned x)
- {
- int b=0;
- for (int b=0; x!=0;)
- {
- x &= (x-1);
- b++;
- }
- return b;
- }
|