OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative numbers, with only two fixed points: a(0) = 0 and a(1) = 1.
LINKS
FORMULA
a(floor(n/2)) = floor(a(n)/2).
abs(a(2*n+1) - a(2*n)) = 1.
a(2^k) = 2^(k+1) - 1 for any k >= 0.
a(2^k-1) = 2^(k-1) for any k > 0.
EXAMPLE
For n = 42:
- the binary expansion of 42 is "101010",
- the corresponding XOR-triangle is:
1 0 1 0 1 0
1 1 1 1 1
0 0 0 0
0 0 0
0 0
0
- the bits on the left diagonal are: 1, 1, 0, 0, 0, 0,
- so a(42) = 2^5 + 2^4 = 48.
PROG
(PARI) a(n) = { my (v=0); forstep (x=#binary(n)-1, 0, -1, if (bittest(n, x), v+=2^x; ); n=bitxor(n, n\2)); return (v) }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, May 09 2020
STATUS
approved