Count the 1-bits · Kira bit 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.
Hitung bit-1
Setiap bilangan bulat tak-ber tanda disimpan dalam bentuk biner. Kembalikan berapa banyak bitnya yang 1 (ini disebut population count). Periksa bit terendah dengan x & 1u, lalu geser x ke kanan satu tempat dengan x >>= 1, sampai x menjadi 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. · Selesaikan int popcount(unsigned x) untuk mengembalikan bilangan bit 1 dalam x. Periksa bit paling rendah dengan x & 1u, kemudian gerakkan ke kanan dengan x >>= 1.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.