Write a program to count set bits in an integer?
unsigned int NumberSetBits(unsigned int n) { unsigned int CountSetBits= 0; while (n) { CountSetBits += n & 1; n >>= 1; } return CountSetBits; }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
need an explanation for this answer? contact us directly to get an explanation for this answer