This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A005351 M4059 #80 Jun 01 2025 05:55:06 %S A005351 0,1,6,7,4,5,26,27,24,25,30,31,28,29,18,19,16,17,22,23,20,21,106,107, %T A005351 104,105,110,111,108,109,98,99,96,97,102,103,100,101,122,123,120,121, %U A005351 126,127,124,125,114,115,112,113,118,119,116,117,74,75,72,73,78,79,76 %N A005351 Base -2 representation for n regarded as base 2, then evaluated. %C A005351 a(n) = n when n is a power of 4. This is because the even-indexed powers of 2 are the same as the even-indexed powers of -2. - _Alonso del Arte_, Feb 09 2012 %C A005351 a(n) = n if n is a sum of distinct powers of 4. - _Michael Somos_, Aug 27 2012 %C A005351 Write n = Sum_{i in b(n)} (-2)^(i - 1), which uniquely determines the set of positive integers b(n). Then a(n) = Sum_{i in b(n)} 2^(i - 1). For example, a(7) = 27 because 7 = (-2)^0 + (-2)^1 + (-2)^3 + (-2)^4 and 27 = 2^0 + 2^1 + 2^3 + 2^4. - _Gus Wiseman_, Jul 26 2019 %D A005351 M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 101. %D A005351 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence). %H A005351 Reinhard Zumkeller, <a href="/A005351/b005351.txt">Table of n, a(n) for n = 0..8191</a> %H A005351 Joerg Arndt, <a href="http://www.jjj.de/fxt/#fxtbook">Matters Computational (The Fxtbook)</a>, p. 58-59 %H A005351 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/Negabinary.html">Negabinary</a> %H A005351 Wikipedia, <a href="http://en.wikipedia.org/wiki/Negative_base">Negative base</a> %H A005351 A. Wilks, <a href="/A005351/a005351.pdf">Email, May 22 1991</a> %F A005351 a(4n+2) = 4a(n+1)+2, a(4n+3) = 4a(n+1)+3, a(4n+4) = 4a(n+1), a(4n+5) = 4a(n+1)+1, n>-2, a(1)=1. - _Ralf Stephan_, Apr 06 2004 %e A005351 2 = 4+(-2)+0 = 110 => 6, 3 = 4+(-2)+1 = 111 => 7, ..., 6 = (16)+(-8)+0+(-2)+0 = 11010 => 26. %t A005351 a[n_] := Module[{t = 2(4^Floor[ Log[4, Abs[n] + 1] + 2] - 1)/3}, BitXor[n + t, t]]; Table[a[n], {n, 0, 60}] (* _Robert G. Wilson v_, Jan 24 2005 *) %o A005351 (Haskell) %o A005351 a005351 0 = 0 %o A005351 a005351 n = a005351 n' * 2 + m where %o A005351 (n', m) = if r < 0 then (q + 1, r + 2) else (q, r) %o A005351 where (q, r) = quotRem n (negate 2) %o A005351 -- _Reinhard Zumkeller_, Jul 07 2012 %o A005351 (Python) %o A005351 def A005351(n): %o A005351 s, q = '', n %o A005351 while q >= 2 or q < 0: %o A005351 q, r = divmod(q, -2) %o A005351 if r < 0: %o A005351 q += 1 %o A005351 r += 2 %o A005351 s += str(r) %o A005351 return int(str(q)+s[::-1],2) # _Chai Wah Wu_, Apr 10 2016 %o A005351 (PARI) a(n) = my(t=(32*4^logint(abs(n)+1,4)-2)/3); bitxor(n+t,t); \\ _Ruud H.G. van Tol_, Oct 18 2023 %Y A005351 Cf. A039724. Complement of A005352. %Y A005351 Cf. A185269 (primes in this sequence). %Y A005351 Cf. A000120, A029931, A035327, A053985, A065359, A070939, A326032. %K A005351 nonn,base,easy,nice,look %O A005351 0,3 %A A005351 _N. J. A. Sloane_ %E A005351 More terms from _Robert G. Wilson v_, Jan 24 2005