Count the 1-bits · 1ビットを数える
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 になるまで続けます。
Complete int popcount(unsigned x) to return the number of 1-bits in x. Check the lowest bit with x & 1u, then shift right with x >>= 1. · int popcount(unsigned x) を完成させて x 内の1ビットの数を返します。x & 1u で最下位ビットをチェックし、x >>= 1 で右シフトします。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。