A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/da/db8/count__of__set__bits_8cpp_source.html below:

TheAlgorithms/C++: bit_manipulation/count_of_set_bits.cpp Source File

Go to the documentation of this file. 39

std ::int64_t n) {

// int64_t is preferred over int so that 40 // no Overflow can be there. 42 int

count = 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 74

std::cout <<

"All test cases successfully passed!"

<< std::endl;

81 test

();

// run self-test implementations

std::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