统计bit中1的个数。与一下即可。
int hammingWeight(uint32_t n) { int ret = 0; while (n > 0) { ret += (n & 1)?1:0; n = n >> 1; } return ret; }
posted on 2018-01-30 10:49 willaty 阅读(107) 评论(0) 编辑 收藏 举报
Powered by: 博客园 Copyright © 2024 willaty Powered by .NET 9.0 on Kubernetes