Count the 1-bits · 1-비트 세기
Count the 1-bits
Every unsigned integer is stored in binary. Return how many of its bits are 1 (this is called the population count). Look at the lowest bit with x & 1u, then shift x right by one with x >>= 1, until x becomes 0.
1비트 세기
모든 부호 없는 정수는 이진수로 저장됩니다. 이 중 1개(이를 인구 수라고 함)가 1인지 반환합니다. x & 1u인 가장 낮은 비트를 확인한 후, x를 x >>= 1으로 한 번씩 오른쪽으로 이동시켜 x이 0이 될 때까지 반복합니다.
Complete int popcount(unsigned x) to return the number of 1-bits in x. Check the lowest bit with x & 1u, then shift right with x >>= 1. · int popcount(unsigned x)를 완성하여 x에 포함된 1-비트의 개수를 반환합니다. 최하위 비트를 x & 1u으로 확인한 후, x >>= 1로 오른쪽 시프트합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.