C code到计数unsigned char型的“1”比特数 [英] C code to count the number of '1' bits in an unsigned char

查看:161
本文介绍了C code到计数unsigned char型的“1”比特数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要C code返回在C. unsigned char类型,我需要一个解释,为什么它的作品,如果它不是很明显1的数量。我发现了很多code为一个32位的号码,但没有多少unsigned char类型。

I need C code to return the number of 1's in an unsigned char in C. I need an explanation as to why it works if it's not obvious. I've found a lot of code for a 32-bit number but not much for an unsigned char.

推荐答案

同样code将为unsigned char类型的工作。遍历测试他们所有位。请参见这个

The same code will work for an unsigned char. Loop over all bits testing them. See this.

这篇关于C code到计数unsigned char型的“1”比特数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆