a & (a-1) =? meaning

& Bits are the mean, the a and a-1 are replaced by binary, then bitwise ANDed, 1 = 0 & 0,1 & 0,0 & 0 = 1 = 1

a-1 a and two values ​​are bitwise AND operation. As a = 10, then a & (a-1) = 10 & 9 = 1010 & 1001 = 1000 = 8.

a & (a-1) complete functions: remove a right side. 1
embodiment: a = 110, then: a & (a-1) = 100
is generally used to count
int COUNT = 0;
the while (a)
{
a = a & (a-. 1 );
COUNT ++;
}

Guess you like

Origin blog.csdn.net/dq932073495/article/details/91475870