login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A322464 Reverse runs of ones in binary expansion of n and convert back to decimal. 2
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 12, 11, 14, 15, 16, 17, 18, 25, 20, 21, 26, 29, 24, 19, 22, 27, 28, 23, 30, 31, 32, 33, 34, 49, 36, 37, 50, 57, 40, 41, 42, 53, 52, 45, 58, 61, 48, 35, 38, 51, 44, 43, 54, 59, 56, 39, 46, 55, 60, 47, 62, 63, 64, 65, 66, 97 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of nonnegative integers.
LINKS
Rémy Sigrist, Colored scatterplot of (n, a(n)) for n = 0..2^18-1 (where the color is function of A005811(n))
FORMULA
A000120(a(n)) = A000120(n).
A005811(a(n)) = A005811(n).
a(A322463(n)) = A322463(a(n)).
a(2^n) = 2^n.
a(2^n-1) = 2^n-1.
EXAMPLE
For n = 150:
- the binary representation of 150 is "10010110",
- we have three runs of ones: "1", "1" and "11",
- we exchange the first and the third run, and the second remains in place,
- we obtain: "11001010",
- hence a(150) = 202.
MATHEMATICA
a[n_] := Module[{s=Split[IntegerDigits[n, 2]]}, m=Length[s]; If[m>1, m2 = m-1 + Mod[m, 2]; ind=Riffle[Range[m2, 1, -2], Range[2, m, 2]]; FromDigits[Flatten[ s[[ind]]], 2], n]]; Array[a, 120, 0] (* Amiram Eldar, Dec 12 2018 *)
PROG
(PARI) a(n) = {
my (r=n, o=[], v=0, p=1, i=0);
while (r, my (l=valuation(r+(r%2), 2)); if (r%2, o=concat(l, o)); r\=2^l);
while (n, my (l=valuation(n+(n%2), 2)); if (n%2, v+=(2^o[i++]-1)*p; p*=2^o[i], p*=2^l); n\=2^l);
return (v);
}
CROSSREFS
See A322463 for the variant where we reverse the runs of zeros.
Sequence in context: A108548 A333692 A333693 * A057889 A235027 A337304
KEYWORD
nonn,base,look
AUTHOR
Rémy Sigrist, Dec 09 2018
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 06:34 EDT 2024. Contains 371920 sequences. (Running on oeis4.)