Skip to content

Count the 1-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.

中文

数 1 的位

每个无符号整数都以二进制存储。返回其中有多少位是 1(这叫做位计数,population count)。用 x & 1u 查看最低位,再用 x >>= 1 把 x 右移一位,直到 x 变为 0。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩