Skip to content · ⁨Pular para o conteúdo⁩

Count the 1-bits · ⁨Contar os 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.

Português

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.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP