Count the 1-bits · Contar os 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.
Conte os bits 1
Todo inteiro sem sinal é armazenado em binário. Retorne quantos dos seus bits são 1 (isso é chamado de contagem de população). Olhe para o bit menos significativo com x & 1u, depois desloque x para a direita em uma posição com x >>= 1, até que x se torne 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. · Complete int popcount(unsigned x) para retornar o número de bits 1 em x. Verifique o bit mais baixo com x & 1u, depois desloque para a direita com x >>= 1.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.