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!)
A246592 Smallest number that can be obtained by swapping 2 adjacent bits in the binary expansion of n. 5
0, 1, 1, 3, 2, 3, 5, 7, 4, 5, 6, 7, 10, 11, 13, 15, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 26, 27, 29, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 40, 41, 42, 43, 44, 45, 46, 47, 52, 53, 54, 55, 58, 59, 61, 63, 32, 33, 34, 35, 36 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,4
COMMENTS
Scanning from the left, find first occurrence of '10' in binary expansion and replace with '01' and return decimal representation or return n if no such swap exists. - Chai Wah Wu, Sep 06 2014
LINKS
EXAMPLE
If n = 9 = 1001_2 then a(9) = 0101_2 = 5.
PROG
(Python)
def A246592(n):
....s = bin(n)[2:]
....for i in range(len(s)-1):
........if s[i:i+2] == '10':
............return int(s[:i]+'01'+s[i+2:], 2)
....else:
........return n # Chai Wah Wu, Sep 06 2014
CROSSREFS
Sequence in context: A050060 A247829 A351705 * A241816 A243109 A206012
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 03 2014
EXTENSIONS
More terms from Alois P. Heinz, Sep 03 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 23 06:04 EDT 2024. Contains 371906 sequences. (Running on oeis4.)