login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A007608 Nonnegative integers in base -4.
(Formerly M0926)
22

%I M0926

%S 0,1,2,3,130,131,132,133,120,121,122,123,110,111,112,113,100,101,102,

%T 103,230,231,232,233,220,221,222,223,210,211,212,213,200,201,202,203,

%U 330,331,332,333,320,321,322,323,310,311,312,313,300,301,302,303,13030

%N Nonnegative integers in base -4.

%C The base 2i representation (quater-imaginary representation) of nonnegative integers is obtained by interleaving with zeros, cf. A212494.

%C More precisely, a(n) is the number n written in base -4; numbers [which represent some nonnegative integer] in base -4 are 0, 1, 2, 3, 100, 101, 102, 103, 110, 111, 112, 113, 120, 121, 122, 123, 130, 131, 132, 133, ... (A212556) - _M. F. Hasler_, May 20 2012

%D D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, 1969, Vol. 2, p. 189.

%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

%H Joerg Arndt, <a href="/A007608/b007608.txt">Table of n, a(n) for n = 0..1000</a>

%H Matthew Szudzik, <a href="https://web.archive.org/web/20130523133059/http://library.wolfram.com/conferences/devconf99/challenge/">A Mathematica programming contest</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/Negabinary.html">Negabinary</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Negative_base">Negative base</a>

%t ToNegaBases[i_Integer, b_Integer] := FromDigits[ Rest[ Reverse[ Mod[ NestWhileList[(#1 - Mod[ #1, b])/-b &, i, #1 != 0 &], b]]]]; Table[ ToNegaBases[n, 4], {n, 0, 55}]

%o (PARI) A007608(n,s="")={until(!n\=-4,s=Str(n%-4,s));eval(s)} \\ _M. F. Hasler_, May 20 2012

%o (Haskell)

%o a007608 0 = 0

%o a007608 n = a007608 n' * 10 + m where

%o (n', m) = if r < 0 then (q + 1, r + 4) else (q, r)

%o where (q, r) = quotRem n (negate 4)

%o -- _Reinhard Zumkeller_, Jul 15 2012

%o (Python)

%o def A007608(n):

%o s, q = '', n

%o while q >= 4 or q < 0:

%o q, r = divmod(q, -4)

%o if r < 0:

%o q += 1

%o r += 4

%o s += str(r)

%o return int(str(q)+s[::-1]) # _Chai Wah Wu_, Apr 09 2016

%Y Cf. A212556 (sorted), A066323 (sum of digits), A212526 (negative integers in base -4).

%Y Other bases: A007090, A039724, A073785, A073786, A073787, A073788, A073789, A073790 & A039723.

%K base,nice,easy,nonn

%O 0,3

%A _N. J. A. Sloane_, _Robert G. Wilson v_, _Mira Bernstein_

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 10 19:06 EDT 2021. Contains 342853 sequences. (Running on oeis4.)