OFFSET

0,3

COMMENTS

This sequence is a self-inverse permutation of the nonnegative integers.

LINKS

FORMULA

a(floor(n/2)) = floor(a(n)/2).

EXAMPLE

For n = 9: the binary expansion of 9 is "1001": the bit at position 2 (0) sits to the right of a 1 so we complement it, the bit at position 4 (1) sits to the right of a 0 so we keep it; the binary expansion of a(9) is "1101" and a(9) = 13.

PROG

(PARI) a(n) = { my (b = binary(n)); forstep (k = 2, #b, 2, if (b[k-1], b[k] = 1-b[k]; ); ); fromdigits(b, 2); }

CROSSREFS

KEYWORD

nonn,base

AUTHOR

Rémy Sigrist, Aug 03 2024

STATUS

approved