나는 popcount (세트 비트의 수)를 수행하는 좋은 방법을 찾았습니다. 나는 몇 가지 예, 그것은 작동하는 진정한에 시도 여기모집단 계산 알고리즘에 대한 약간의 설명을 던지십시오.
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for(c = 0; v; c++)
{
v &= v - 1; // clear the least significant bit set
}
이 하나를 발견했다. 이진 연산/표현의 어떤 속성이 작동하게합니까?
popcount 및 이진 표현에 대한 추가 정보가 있습니까?
무엇이 좋을까요? pch. 그것도 편집 할 수 없습니다 : facepalm : – Prasanth