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 ימינה ב-1 עם x >>= 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) כדי להחזיר את מספר בתי ה-1 ב x. בדוק את הבית הנמוך ביותר עם x & 1u, ולאחר מכן הזז ימינה עם x >>= 1.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.