std ::int64_t n) {
// int64_t is preferred over int so that 40 // no Overflow can be there. 42 intcount = 0;
// "count" variable is used to count number of set-bits('1') 43 // in binary representation of number 'n' 49 // Why this algorithm is better than the standard one? 50 // Because this algorithm runs the same number of times as the number of 51 // set-bits in it. Means if my number is having "3" set bits, then this 52 // while loop will run only "3" times!! 54}
// namespace count_of_set_bits 55}
// namespace bit_manipulation 74std::cout <<
"All test cases successfully passed!"<< std::endl;
81 test();
// run self-test implementationsstd::uint64_t countSetBits(std ::int64_t n)
The main function implements set bit count.
int main()
Main function.
static void test()
Self-test implementations.
Functions for the count sets bits implementation.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4