TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
[Next higher number with same number of set bits] (https://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/) implementation More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
Functions | |
uint64_t | bit_manipulation::next_higher_number (uint64_t x) |
The main function implements checking the next number. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
[Next higher number with same number of set bits] (https://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/) implementation
Given a number x, find next number with same number of 1 bits in it’s binary representation. For example, consider x = 12, whose binary representation is 1100 (excluding leading zeros on 32 bit machine). It contains two logic 1 bits. The next higher number with two logic 1 bits is 17 (100012).
A binary number consists of two digits. They are 0 & 1. Digit 1 is known as set bit in computer terms.
Definition in file next_higher_number_with_same_number_of_set_bits.cpp.
int main | ( | void | ) |
Main function.
Definition at line 98 of file next_higher_number_with_same_number_of_set_bits.cpp.
|
static |
Self-test implementations.
Definition at line 74 of file next_higher_number_with_same_number_of_set_bits.cpp.