Skip to content · ⁨Saltar al contenido⁩

Count the 1-bits · ⁨Contar los bits 1⁩

English

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.

Español

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.

Log in or create account · ⁨Iniciar sesión o crear cuenta⁩

IGCSE, A-Level & AP