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.
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
Offset: 0
Examples
If n = 17 = 10001_2 then a(17) = 10010_2 = 18.
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..8192
Programs
-
Mathematica
A246594[n_] := FromDigits[StringReplace[IntegerString[n, 2], "01" -> "10", 1], 2]; Array[A246594, 100, 0] (* Paolo Xausa, Mar 07 2025 *)
-
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
Extensions
Corrected definition and more terms from Alois P. Heinz, Sep 04 2014
Corrected typo in definition - Chai Wah Wu, Sep 06 2014
Comments