diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html new file mode 100644 index 000000000..f57fecb10 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html @@ -0,0 +1,237 @@ + + + + + + + +Algorithms_in_C++: bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp File Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Algorithms_in_C++ 1.0.0 +
+
Set of algorithms implemented in C++.
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+ +
next_higher_number_with_same_number_of_set_bits.cpp File Reference
+
+
+ +

[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 <iostream>
+
+Include dependency graph for next_higher_number_with_same_number_of_set_bits.cpp:
+
+
+
+
+ + + + +

+Namespaces

namespace  bit_manipulation
 for IO operations
 
+ + + + + + + + + + +

+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.
 
+

Detailed Description

+

[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.

Author
Kunal Nayak
+

Function Documentation

+ +

◆ main()

+ +
+
+ + + + + + + + +
int main (void )
+
+ +

Main function.

+
Returns
0 on exit
+
100 {
+
101 test(); // run self-test implementations
+
102 return 0;
+
103}
+
static void test()
Self-test implementations.
Definition next_higher_number_with_same_number_of_set_bits.cpp:76
+
+Here is the call graph for this function:
+
+
+
+ +
+
+ +

◆ test()

+ +
+
+ + + + + +
+ + + + + + + +
static void test ()
+
+static
+
+ +

Self-test implementations.

+
Returns
void
+
76 {
+
77 // x = 4 return 8
+ +
79 // x = 6 return 9
+ +
81 // x = 13 return 14
+ +
83 // x = 64 return 128
+
84 assert(bit_manipulation::next_higher_number(64) == 128);
+
85 // x = 15 return 23
+ +
87 // x= 32 return 64
+ +
89 // x = 97 return 98
+ +
91 // x = 1024 return 2048
+
92 assert(bit_manipulation::next_higher_number(1024) == 2048);
+
93
+
94 std::cout << "All test cases have successfully passed!" << std::endl;
+
95}
+ +
T endl(T... args)
+
uint64_t next_higher_number(uint64_t x)
The main function implements checking the next number.
Definition next_higher_number_with_same_number_of_set_bits.cpp:31
+
+Here is the call graph for this function:
+
+
+
+ +
+
+
+
+ + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.js b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.js new file mode 100644 index 000000000..28e98dc90 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.js @@ -0,0 +1,6 @@ +var next__higher__number__with__same__number__of__set__bits_8cpp = +[ + [ "main", "d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ], + [ "next_higher_number", "d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html#a4b76571a2a04fa99c30a96eca9997f0e", null ], + [ "test", "d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ] +]; \ No newline at end of file diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 000000000..9265c90e0 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 000000000..44a3523b2 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +88850cab1d66343ce66cdf5b4cc94862 \ No newline at end of file diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 000000000..89803da1f --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,83 @@ + + + + + + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +std::endl + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +bit_manipulation::next +_higher_number + + + + + +Node1->Node3 + + + + + + + + + + + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg new file mode 100644 index 000000000..f86b34b7f --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg @@ -0,0 +1,58 @@ + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +std::endl + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +bit_manipulation::next +_higher_number + + + + + +Node1->Node3 + + + + + + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map new file mode 100644 index 000000000..26c851f08 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 new file mode 100644 index 000000000..53a3d5ef8 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -0,0 +1 @@ +f26d8a8e0cdf8e54a9a3cc4ebce15bf8 \ No newline at end of file diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg new file mode 100644 index 000000000..e01693f83 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::endl + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +bit_manipulation::next +_higher_number + + + + + +Node2->Node4 + + + + + + + + + + + + + diff --git a/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg new file mode 100644 index 000000000..03867f5e3 --- /dev/null +++ b/d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg @@ -0,0 +1,76 @@ + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::endl + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +bit_manipulation::next +_higher_number + + + + + +Node2->Node4 + + + + + + + + diff --git a/d5/d88/md__d_i_r_e_c_t_o_r_y.html b/d5/d88/md__d_i_r_e_c_t_o_r_y.html index ee098a0ce..7e8c25442 100644 --- a/d5/d88/md__d_i_r_e_c_t_o_r_y.html +++ b/d5/d88/md__d_i_r_e_c_t_o_r_y.html @@ -123,6 +123,7 @@ Bit Manipulation
  • Count Of Trailing Ciphers In Factorial N
  • Find Non Repeating Number
  • Hamming Distance
  • +
  • next higher number with same number of set bits
  • Power Of 2
  • Set Kth Bit
  • Travelling Salesman Using Bit Manipulation
  • diff --git a/d7/d81/namespacebit__manipulation.html b/d7/d81/namespacebit__manipulation.html index d178c5191..5cb1b3584 100644 --- a/d7/d81/namespacebit__manipulation.html +++ b/d7/d81/namespacebit__manipulation.html @@ -108,6 +108,9 @@ $(document).ready(function(){initNavTree('d7/d81/namespacebit__manipulation.html + + + @@ -163,6 +166,70 @@ Functions + +

    ◆ next_higher_number()

    + +
    +
    +

    Functions

    uint64_t next_higher_number (uint64_t x)
     The main function implements checking the next number.
     
    bool isPowerOfTwo (std ::int64_t n)
     The main function implements check for power of 2.
     
    + + + + + + + +
    uint64_t bit_manipulation::next_higher_number (uint64_t x)
    +
    + +

    The main function implements checking the next number.

    +
    Parameters
    + + +
    xthe number that will be calculated
    +
    +
    +
    Returns
    a number
    +
    32{
    +
    33
    +
    34 uint64_t rightOne;
    +
    35 uint64_t nextHigherOneBit;
    +
    36 uint64_t rightOnesPattern;
    +
    37
    +
    38 uint64_t next = 0;
    +
    39
    +
    40 if(x)
    +
    41 {
    +
    42
    +
    43 // right most set bit
    +
    44 rightOne = x & -(signed)x;
    +
    45
    +
    46 // reset the pattern and set next higher bit
    +
    47 // left part of x will be here
    +
    48 nextHigherOneBit = x + rightOne;
    +
    49
    +
    50 // nextHigherOneBit is now part [D] of the above explanation.
    +
    51
    +
    52 // isolate the pattern
    +
    53 rightOnesPattern = x ^ nextHigherOneBit;
    +
    54
    +
    55 // right adjust pattern
    +
    56 rightOnesPattern = (rightOnesPattern)/rightOne;
    +
    57
    +
    58 // correction factor
    +
    59 rightOnesPattern >>= 2;
    +
    60
    +
    61 // rightOnesPattern is now part [A] of the above explanation.
    +
    62
    +
    63 // integrate new pattern (Add [D] and [A])
    +
    64 next = nextHigherOneBit | rightOnesPattern;
    +
    65 }
    +
    66
    +
    67 return next;
    +
    68}
    +
    +
    + diff --git a/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.map b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.map new file mode 100644 index 000000000..a696ddbcd --- /dev/null +++ b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.md5 b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.md5 new file mode 100644 index 000000000..a00bf9ded --- /dev/null +++ b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.md5 @@ -0,0 +1 @@ +cee136b162973d12df81f1bb9920b6e9 \ No newline at end of file diff --git a/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.svg b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.svg new file mode 100644 index 000000000..4d2027fec --- /dev/null +++ b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl.svg @@ -0,0 +1,84 @@ + + + + + + + + + + + +bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp + + +Node1 + + +bit_manipulation/next +_higher_number_with_same +_number_of_set_bits.cpp + + + + + +Node2 + + +cassert + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +iostream + + + + + +Node1->Node3 + + + + + + + + + + + + + diff --git a/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl_org.svg b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl_org.svg new file mode 100644 index 000000000..a67e2289f --- /dev/null +++ b/d9/deb/next__higher__number__with__same__number__of__set__bits_8cpp__incl_org.svg @@ -0,0 +1,59 @@ + + + + + + +bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp + + +Node1 + + +bit_manipulation/next +_higher_number_with_same +_number_of_set_bits.cpp + + + + + +Node2 + + +cassert + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +iostream + + + + + +Node1->Node3 + + + + + + + + diff --git a/dir_f3c4fbc4e901afa0a54d0623c5574aa7.html b/dir_f3c4fbc4e901afa0a54d0623c5574aa7.html index e7f427f77..655bf9bd4 100644 --- a/dir_f3c4fbc4e901afa0a54d0623c5574aa7.html +++ b/dir_f3c4fbc4e901afa0a54d0623c5574aa7.html @@ -118,6 +118,9 @@ Files  hamming_distance.cpp  Returns the Hamming distance between two integers.
      + next_higher_number_with_same_number_of_set_bits.cpp + [Next higher number with same number of set bits] (https://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/) implementation
     power_of_2.cpp  [Find whether a given number is power of 2] (https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/) implementation
      diff --git a/dir_f3c4fbc4e901afa0a54d0623c5574aa7.js b/dir_f3c4fbc4e901afa0a54d0623c5574aa7.js index 78662bfae..dff96a6a7 100644 --- a/dir_f3c4fbc4e901afa0a54d0623c5574aa7.js +++ b/dir_f3c4fbc4e901afa0a54d0623c5574aa7.js @@ -5,6 +5,7 @@ var dir_f3c4fbc4e901afa0a54d0623c5574aa7 = [ "count_of_trailing_ciphers_in_factorial_n.cpp", "da/d50/count__of__trailing__ciphers__in__factorial__n_8cpp.html", "da/d50/count__of__trailing__ciphers__in__factorial__n_8cpp" ], [ "find_non_repeating_number.cpp", "d6/d38/find__non__repeating__number_8cpp.html", "d6/d38/find__non__repeating__number_8cpp" ], [ "hamming_distance.cpp", "d4/d48/hamming__distance_8cpp.html", "d4/d48/hamming__distance_8cpp" ], + [ "next_higher_number_with_same_number_of_set_bits.cpp", "d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp.html", "d5/d1e/next__higher__number__with__same__number__of__set__bits_8cpp" ], [ "power_of_2.cpp", "dc/d6d/power__of__2_8cpp.html", "dc/d6d/power__of__2_8cpp" ], [ "set_kth_bit.cpp", "d5/db5/set__kth__bit_8cpp.html", "d5/db5/set__kth__bit_8cpp" ], [ "travelling_salesman_using_bit_manipulation.cpp", "d4/d8f/travelling__salesman__using__bit__manipulation_8cpp.html", "d4/d8f/travelling__salesman__using__bit__manipulation_8cpp" ] diff --git a/files.html b/files.html index 94d6edd45..7b48d6e97 100644 --- a/files.html +++ b/files.html @@ -122,9 +122,10 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm  count_of_trailing_ciphers_in_factorial_n.cppCount the number of ciphers in n! implementation  find_non_repeating_number.cppImplementation to find the non repeating integer in an array of repeating integers. Single Number  hamming_distance.cppReturns the Hamming distance between two integers - power_of_2.cpp[Find whether a given number is power of 2] (https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/) implementation - set_kth_bit.cppImplementation to [From the right, set the Kth bit in the binary representation of N] (https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1/) in an integer - travelling_salesman_using_bit_manipulation.cppImplementation to [Travelling Salesman problem using bit-masking] (https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/) + next_higher_number_with_same_number_of_set_bits.cpp[Next higher number with same number of set bits] (https://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/) implementation + power_of_2.cpp[Find whether a given number is power of 2] (https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/) implementation + set_kth_bit.cppImplementation to [From the right, set the Kth bit in the binary representation of N] (https://practice.geeksforgeeks.org/problems/set-kth-bit3724/1/) in an integer + travelling_salesman_using_bit_manipulation.cppImplementation to [Travelling Salesman problem using bit-masking] (https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/)   ciphers  a1z26_cipher.cppImplementation of the A1Z26 cipher  atbash_cipher.cppAtbash Cipher implementation diff --git a/globals_func_m.html b/globals_func_m.html index c11581063..3c982ac27 100644 --- a/globals_func_m.html +++ b/globals_func_m.html @@ -100,7 +100,7 @@ $(document).ready(function(){initNavTree('globals_func_m.html',''); initResizabl
    Here is a list of all documented functions with links to the documentation:

    - m -