login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A038189
Bit to left of least significant 1-bit in binary expansion of n.
22
0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1
OFFSET
0,1
COMMENTS
Characteristic function of A091067.
Image, under the coding i -> floor(i/2), of the fixed point, starting with 0, of the morphism 0 -> 01, 1 -> 02, 2 -> 32, 3 -> 31. - Jeffrey Shallit, May 15 2016
Restricted to the positive integers, completely additive modulo 2. - Peter Munn, Jun 20 2022
If a(n) is defined as 1-a(-n) for all n<0, then a(n) = a(2*n), a(4*n+1) = 0, a(4*n+3) = 1 for all n in Z. - Michael Somos, Oct 05 2024
REFERENCES
Jean-Paul Allouche and Jeffrey O. Shallit, Automatic sequences, Cambridge, 2003, sect. 5.1.6
FORMULA
a(0) = 0, a(2*n) = a(n) for n>0, a(4*n+1) = 0, a(4*n+3) = 1.
G.f.: Sum_{k>=0} t^3/(1-t^4), where t=x^2^k. Parity of A025480. For n >= 1, a(n) = 1/2 * (1 - (-1)^A025480(n-1)). - Ralf Stephan, Jan 04 2004 [index adjusted by Peter Munn, Jun 22 2022]
a(n) = 1 if Kronecker(-n,m)=Kronecker(m,n) for all m, otherwise a(n)=0. - Michael Somos, Sep 22 2005
a(n) = 1 iff A164677(n) < 0. - M. F. Hasler, Aug 06 2015
For n >= 1, a(n) = A065339(n) mod 2. - Peter Munn, Jun 20 2022
From A.H.M. Smeets, Mar 08 2023: (Start)
a(n+1) = 1 - A014577(n) for n >= 0.
a(n+1) = 2 - A014710(n) for n >= 0.
a(n) = (1 - A034947(n))/2 for n > 0. (End)
Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 1/2. - Amiram Eldar, Aug 30 2024
EXAMPLE
a(6) = 1 since 6 = 110 and bit before rightmost 1 is a 1.
MAPLE
A038189 := proc(n)
option remember;
if n = 0 then
0 ;
elif type(n, 'even') then
procname(n/2) ;
elif modp(n, 4) = 1 then
0 ;
else
1 ;
end if;
end proc:
seq(A038189(n), n=0..100) ; # R. J. Mathar, Mar 30 2018
MATHEMATICA
f[n_] := Block[{id2 = Join[{0}, IntegerDigits[n, 2]]}, While[ id2[[-1]] == 0, id2 = Most@ id2]; id2[[-2]]]; f[0] = 0; Array[f, 105, 0] (* Robert G. Wilson v, Apr 14 2009 and fixed Feb 27 2014 *)
f[n_] := f[n] = Switch[Mod[n, 4], 0, f[n/2], 1, 0, 2, f[n/2], 3, 1]; f[0] = 0; Array[f, 105, 0] (* Robert G. Wilson v, Apr 14 2009, fixed Feb 27 2014 *)
a[ n_] := If[n==0, 0, Mod[(n/2^IntegerExponent[n, 2]-1)/2, 2]]; (* Michael Somos, Oct 05 2024 *)
PROG
(C) int a(int n) { return (n & ((n&-n)<<1)) ? 1 : 0; } /* from Russ Cox */
(PARI) {a(n) = if(n==0, 0, ((n/2^valuation(n, 2)-1)/2)%2)}; /* Michael Somos, Sep 22 2005 */
(PARI) a(n) = if(n<3, 0, prod(m=1, n, kronecker(-n, m)==kronecker(m, n))) /* Michael Somos, Sep 22 2005 */
(PARI) A038189(n)=bittest(n, valuation(n, 2)+1) \\ M. F. Hasler, Aug 06 2015
(PARI) a(n)=my(h=bitand(n, -n)); n=bitand(n, h<<1); n!=0; \\ Joerg Arndt, Apr 09 2021
(Magma)
function a (n)
if n eq 0 then return 0; // alternatively, return 1;
else while IsEven(n) do n := n div 2; end while; end if;
return n div 2 mod 2; end function;
nlo := 0; nhi := 32;
[a(n) : n in [nlo..nhi] ]; // Fred Lunnon, Mar 27 2018
(Python)
def A038189(n):
s = bin(n)[2:]
m = len(s)
i = s[::-1].find('1')
return int(s[m-i-2]) if m-i-2 >= 0 else 0 # Chai Wah Wu, Apr 08 2021
CROSSREFS
A014707(n)=a(n+1). A014577(n)=1-a(n+1).
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - N. J. A. Sloane, Jul 27 2012
Related sequences A301848, A301849, A301850. - Fred Lunnon, Mar 27 2018
Sequence in context: A288508 A262588 A234577 * A072783 A353478 A353555
KEYWORD
nonn,easy,base
AUTHOR
Fred Lunnon, Dec 11 1999
EXTENSIONS
More terms from David W. Wilson
Definition corrected by Russ Cox and Ralf Stephan, Nov 08 2004
STATUS
approved