Count the 1-bits · Contar los 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.
Contar los bits en 1
Cada entero sin signo se almacena en binario. Devuelve cuántos de sus bits son 1 (esto se conoce como cuenta de población). Observa el bit menos significativo con x & 1u, luego desplaza x una posición a la derecha con x >>= 1, hasta que x se convierta en 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 devolver el número de bits 1 en x. Verifique el bit más bajo con x & 1u, luego desplazar a la derecha con x >>= 1.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.