TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation to [count number of set bits of a number] (https://www.geeksforgeeks.org/count-set-bits-in-an-integer/) in an integer. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
namespace | count_of_set_bits |
Functions for the count sets bits implementation. | |
Functions | |
std::uint64_t | bit_manipulation::count_of_set_bits::countSetBits (std ::int64_t n) |
The main function implements set bit count. | |
static void | test () |
int | main () |
Main function. | |
Implementation to [count number of set bits of a number] (https://www.geeksforgeeks.org/count-set-bits-in-an-integer/) in an integer.
We are given an integer number. We need to calculate the number of set bits in it.
A binary number consists of two digits. They are 0 & 1. Digit 1 is known as set bit in computer terms. Worst Case Time Complexity: O(log n) Space complexity: O(1)
Definition in file count_of_set_bits.cpp.
std::uint64_t bit_manipulation::count_of_set_bits::countSetBits | ( | std ::int64_t | n | ) |
The main function implements set bit count.
n | is the number whose set bit will be counted |
n
Definition at line 38 of file count_of_set_bits.cpp.
int main | ( | void | ) |
Main function.
Definition at line 80 of file count_of_set_bits.cpp.
|
static |
Definition at line 57 of file count_of_set_bits.cpp.