login
A345352
The binary expansion of a(n) is obtained by left-padding the binary expansion of n with 0's so that it has 2^k digits for some k > 0 as small as possible and then reversing the first half and the second half of this binary expansion.
2
0, 1, 2, 3, 8, 10, 9, 11, 4, 6, 5, 7, 12, 14, 13, 15, 128, 136, 132, 140, 130, 138, 134, 142, 129, 137, 133, 141, 131, 139, 135, 143, 64, 72, 68, 76, 66, 74, 70, 78, 65, 73, 69, 77, 67, 75, 71, 79, 192, 200, 196, 204, 194, 202, 198, 206, 193, 201, 197, 205
OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers with infinitely many fixed points (A345362).
FORMULA
A000120(a(n)) = A000120(n).
a(A001196(n)) = A001196(a(n)).
a(n) < 2^2^k for any n < 2^2^k.
a(2^k) = 2^A054429(k) for any k > 0.
EXAMPLE
For n = 43:
- the binary expansion of n is "101011",
- it has 6 binary digits, so we pad it with 2 leading 0's,
- the first half is "0010" and its reversal is "0100",
- the second half is "1011" and its reversal is "1101",
- so the binary expansion of a(43) is "01001101",
- and a(43) = 77.
PROG
(PARI) a(n) = { my (b=binary(n), x); for (k=1, oo, x=2^k-#b; if (x>=0, b=concat(vector(x), b); return (fromdigits(concat(Vecrev(b[1..#b/2]), Vecrev(b[#b/2+1..#b])), 2)))) }
(Python)
def a(n):
b = bin(n)[2:]
bb = bin(len(b))[2:]
if bb != '1' + '0'*(len(bb)-1): b = '0'*(2**len(bb) - len(b)) + b
return int(b[:len(b)//2][::-1] + b[len(b)//2:][::-1], 2)
print([a(n) for n in range(60)]) # Michael S. Branicky, Jun 15 2021
CROSSREFS
Cf. A000120, A001196, A054429, A345362 (fixed points).
Sequence in context: A019307 A342849 A247580 * A028742 A028771 A023709
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Jun 15 2021
STATUS
approved