01111111 127
01111110 126
127 & 126 = 01111110
01011000 88
01010111 87
88 & 87 = 01010000
若要應用嘛,可用在想找出有幾個bit on的情況:
int quickBitcount(unsigned x) { int count = 0; while (x) { x &= (x-1); count++; } return count; }
from:http://sevensavants.blogspot.com/2010/01/x-x-x-1-trick.html
0 意見:
張貼留言