OFFSET
0,2
COMMENTS
This is a self-inverse permutation of the positive integers.
LINKS
EXAMPLE
a(4) = 12 since 4 = 100 binary -> 1100 = 12 decimal,
a(5) = 27 since 5 = 101 binary -> 110011 = 27 decimal,
a(6) = 2 since 6 = 110 binary -> 10 = 2 decimal.
MATHEMATICA
Table[FromDigits[#, 2] &@ Flatten[If[First@ # == 1, If[OddQ@ Length@ #, Append[IntegerDigits@ #, 1], Most@ IntegerDigits@ #], #] & /@ Split@ IntegerDigits[n, 2]], {n, 63}] (* Michael De Vlieger, Dec 22 2015 *)
PROG
(PARI) a(n) = if (n==0, 0, my (b=n%2, r=valuation(n+b, 2), rr=if (b==0, r, r%2, r+1, r-1)); (a(n\2^r)+b)*2^rr-b) \\ Rémy Sigrist, Jan 20 2019
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Alex Ratushnyak, Dec 21 2015
EXTENSIONS
a(0) = 0 prepended by Rémy Sigrist, Jan 20 2019
STATUS
approved