Skip to content · ⁨Passer au contenu⁩

Count the 1-bits · ⁨Compter les 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.

Français

Compter les bits à 1

Chaque entier non signé est stocké en binaire. Renvoyez le nombre de ses bits qui sont 1 (on appelle cela la population count). Regardez le bit le plus bas avec x & 1u, puis décalez x vers la droite d'un cran avec x >>= 1, jusqu'à ce que x devienne 0.

Log in or create account · ⁨Se connecter ou créer un compte⁩

IGCSE, A-Level & AP