C语言问题,Count the 1 Bits of a 64-bit Value

望各位帮忙看看,现在就想要答案,蟹蟹各位潜水专家,感谢解答,感谢回答,感谢解答。在“PUT YOUR CODE HERE”写内容,前面内容不要改动,按照要求来编写。

// count bits in a uint64_t

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>

// return how many 1 bits value contains
int bit_count(uint64_t value) {
    // PUT YOUR CODE HERE

    return 42;
}

img

// count bits in a uint64_t
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// return how many 1 bits value contains
int bit_count(uint64_t value) {
    int count = 0;
    while(value > 0)
    {
        if(value&1==1)
            count++;
        value = value>>1;
    }
    return count;
}
 
int main()
{
      uint64_t n,m;
      scanf("0x%llx",&n);
      m = bit_count(n);
      printf("%d",m);
      system("pause");
      return 0;
}
// count bits in a uint64_t
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
// return how many 1 bits value contains
int bit_count(uint64_t value) {
    int sum = 0;
    while(value>0){
        if (value&0x1)
            sum++;
        value >>= 1;
    }
    return sum;
}
int main(int argc, char const *argv[])
{
    printf("%d\n",bit_count((uint64_t)0xffffffffffffffff));
    printf("%d\n",bit_count((uint64_t)0x8000000000000001));
    return 0;
}

img