login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A246594 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two adjacent bits in the binary expansion of n. 5
0, 1, 2, 3, 4, 6, 6, 7, 8, 10, 12, 13, 12, 14, 14, 15, 16, 18, 20, 21, 24, 25, 26, 27, 24, 26, 28, 29, 28, 30, 30, 31, 32, 34, 36, 37, 40, 41, 42, 43, 48, 49, 50, 51, 52, 53, 54, 55, 48, 50, 52, 53, 56, 57, 58, 59, 56, 58, 60, 61, 60, 62, 62, 63, 64, 66, 68 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
COMMENTS
In both this sequence and A246593 you are not allowed to touch any of the invisible 0's before the leading 1.
Scanning from the left, find first occurrence of '01' in binary expansion and replace with '10' and return decimal representation or return n if no such swap exists. - Chai Wah Wu, Sep 06 2014
LINKS
EXAMPLE
If n = 17 = 10001_2 then a(17) = 10010_2 = 18.
PROG
(Python)
def A246594(n):
....s = bin(n)[2:]
....for i in range(len(s)-1):
........if s[i:i+2] == '01':
............return int(s[:i]+'10'+s[i+2:], 2)
....else:
........return n # Chai Wah Wu, Sep 06 2014
CROSSREFS
Sequence in context: A106006 A364104 A050460 * A175808 A334666 A163380
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 03 2014
EXTENSIONS
Corrected definition and more terms from Alois P. Heinz, Sep 04 2014
Corrected typo in definition - Chai Wah Wu, Sep 06 2014
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 01:35 EDT 2024. Contains 371964 sequences. (Running on oeis4.)