Sunday, May 1, 2011
Next Higher Number with Same Number of Set Bits
1 - May - 2011
Given a number say, N - an integer. Find the next larger number with same set (logic 1) number of bits.
For example consider N = 156 which is 10011100 in binary. It has 4 bits set to logic 1. The next immediate number with 4 bits set to logic 1 is 163.
Try out the solution and compare it with my post on Geeksforgeeks. Again I am posting it as a reference to Geeksforgeeks link.
If any clarification needed, post your comments there. They will be helpful to many engineers visiting Geeksforgeeks.