Since we want the smallest next value , shift all 1 ' s ▁ at ▁ the ▁ end ▁ in ▁ the ▁ binary ▁ ▁ substring ▁ starting ▁ from ▁ index ▁ ' i + 2
' NEW_LINE INDENT j = i + 2 NEW_LINE k = l - 1 NEW_LINE while ( j < k ) : NEW_LINE INDENT if ( bnum [ j ] == '1' and bnum [ k ] == '0' ) : NEW_LINE INDENT ch = bnum [ j ] NEW_LINE bnum [ j ] = bnum [ k ] NEW_LINE bnum [ k ] = ch NEW_LINE j += 1 NEW_LINE k -= 1 NEW_LINE DEDENT DEDENT DEDENT