Number of 1 Bits
来源:互联网 发布:sql注入怎么过安全狗 编辑:程序博客网 时间:2024/06/06 11:49
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011
, so the function should return 3.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
int hammingWeight(uint32_t n) { int num_bits = 0; while(n != 0) { if (n & 1) { ++num_bits; } n = n >> 1; } return num_bits;}
阅读全文
0 0
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- Number of 1 Bits
- camera2 (api2)打开预览过程(二)
- JVM(Java虚拟机)优化大全和案例实战
- android使用fir.im实现版本更新
- SSL验证时,CSR文件的生成
- 通过ftp上传文件到指定服务器
- Number of 1 Bits
- [数算] 研究了一天的《N个球放M个盒子问题》~~~~~~~~~~~~8种情况全部用公式解决 [复制链接]
- 线程
- Bean标签的常用属性
- 一步步深入Java底层原理(三)
- ABAP--C语言调用SAP的RFC的代码样例
- js获取上一个月、下一个月
- 集合
- 百度搜索引擎的工作原理 鏀惰棌鍒帮細 时间:2015-07-10 文章来源:马海祥博客 访问次数:4330 关于百度以及其它搜索引擎的工作原理,其实大家已经讨论过很多,但随着科技的进步、互联网