惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - octoberfirst

Service注册发现及其调用-分布式服务框架 比较成熟的支持数据分票的数据库产品 CodeCommit on Amazon AWS 使用yeoman来搭建webapp脚手架 5美元的互联网硬件主板 互联网创业的逻辑 Pyramid, Django, 和 Flask 51 Best DevOps Tools for #DevOps Engineers 目前的流行的一些开源框架 bank business Use HttpApplication.CompleteRequest Instead of Response.End A low-level Look at the ASP.NET Architecture Bit-tricks and other nifty little snippets. Endianess The best method for counting bits in a 32-bit integer(2) Scalability Best Practices: Lessons from eBay Changes to JavaScript, Part 1: EcmaScript 5 Enterprise Service Bus Overview Inheriting From a Native C++ Class in C# - octoberfirst
The best method for counting bits in a 32-bit integer
octoberfirst · 2010-03-13 · via 博客园 - octoberfirst
B[0] = 0x55555555 = 01010101 01010101 01010101 01010101
B[1] = 0x33333333 = 00110011 00110011 00110011 00110011
B[2] = 0x0F0F0F0F = 00001111 00001111 00001111 00001111
B[3] = 0x00FF00FF = 00000000 11111111 00000000 11111111
B[4] = 0x0000FFFF = 00000000 00000000 11111111 11111111

The best method for counting bits in a 32-bit integer v is the following:

v = v - ((v >> 1) & 0x55555555);                    // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count

http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel 












B[0] = 0x55555555 = 01010101 01010101 01010101 01010101





B[1] = 0x33333333 = 00110011 00110011 00110011 00110011





B[2] = 0x0F0F0F0F = 00001111 00001111 00001111 00001111





B[3] = 0x00FF00FF = 00000000 11111111 00000000 11111111





B[4] = 0x0000FFFF = 00000000 00000000 11111111 11111111















The best method for counting bits in a 32-bit integer v is the following:












v = v - ((v >> 1) & 0x55555555);                    // reuse input as temporary




v = (v & 0x33333333) + ((v >> 2) & 0x33333333);     // temp






c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count 1





 01010101  01010101  01010101  01010101




v=

00000111




v >> 1


00000011




((v >> 1) & 0x55555555) 00000000 00000000 00000000 00000001





11111111 11111111 11111111 11111111




v = v - ((v >> 1) & 0x55555555);            10000000 00000000 00000000 00000110





00110011 00110011 00110011 00110011




 (v & 0x33333333) 00000000 00000000 00000000 00000010




 ((v >> 2) & 0x33333333);


00000001








00000011 0x1010101







 00000001000000010000000100000001






00000001000000010000000100000001

c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count 00000011