今天遇到的一个问题,感觉自己的代码效率不高
编写一个函数,实现统计一个字符串中bit为1的个数
#include <stdio.h>
//方法1
int str_bit_count(char * p)
{
int count = 0,sum = 0;
int n = 0;
while((*p) != '\0')
{
n = *p;
for(count=0;n;n>>=1)
{
count += n&1;
}