OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
LINKS
FORMULA
EXAMPLE
For n = 43: the binary expansion of 43 is "101011", and has Hamming weight 4, reversing the 4 rightmost bits yields "101101", so a(43) = 45.
PROG
(PARI) a(n) = { my (b = binary(n), w = hammingweight(n)); fromdigits(concat( b[1..#b-w], Vecrev(b[#b-w+1..#b])), 2); }
(Python)
def a(n): w, b = n.bit_count(), bin(n)[2:]; return int(b[:-w]+b[-w:][::-1], 2)
print([a(n) for n in range(68)]) # Michael S. Branicky, May 24 2024
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, May 20 2024
STATUS
approved