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 ימינה ב-1 עם x >>= 1, עד שx הופך ל0.

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP