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 が含まれる個数を返してください(これをポピュレーションカウントと呼びます)。 x & 1u で最下位ビットを確認し、 x を x >>= 1 で1つシフトして右へ移動させ、 x が 0 になるまで続けます。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP