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!)
A129760 Bitwise AND of binary representation of n-1 and n. 29

%I #52 Jul 13 2022 12:28:55

%S 0,0,2,0,4,4,6,0,8,8,10,8,12,12,14,0,16,16,18,16,20,20,22,16,24,24,26,

%T 24,28,28,30,0,32,32,34,32,36,36,38,32,40,40,42,40,44,44,46,32,48,48,

%U 50,48,52,52,54,48,56,56,58,56,60,60,62,0,64,64,66,64,68,68,70,64,72,72,74

%N Bitwise AND of binary representation of n-1 and n.

%C Also the number of Ducci sequences with period n.

%C Also largest number less than n having in binary representation fewer ones than n has; A048881(n-1) = A000120(a(n)) = A000120(n)-1. - _Reinhard Zumkeller_, Jun 30 2010

%C a(n) is the parent of vertex n in the binomial tree. The binomial tree is root vertex n=0, then for n>=1 the parent of n is n with its least significant 1-bit changed to a 0-bit. Binomial tree order 5, n=0 to 31 inclusive, is the frontispiece of Knuth volume 1, second and subsequent editions. Vertices are shown there with n in binary dots and a(n) is the next vertex towards the root at the bottom of the page. - _Kevin Ryde_, Jul 24 2019

%D Donald E. Knuth, The Art of Computer Programming, volume 1, second edition, frontispiece. Reproduced with brief description of the art in Donald E. Knuth, Selected Papers on Fun and Games, 2010, Chapter 47 Geek Art, figure 16, page 679.

%H Reinhard Zumkeller, <a href="/A129760/b129760.txt">Table of n, a(n) for n = 1..10000</a>

%H Ron Brown and Jonathan L. Merzel, <a href="http://www.fq.math.ca/Papers1/45-2/brown.pdf">The number of Ducci sequences with a given period</a>, Fib. Quart., 45 (2007), 115-121.

%F a(n) = n AND n-1.

%F Equals n - A006519(n). - _N. J. A. Sloane_, May 26 2008

%F From _Johannes W. Meijer_, Jun 22 2011: (Start)

%F a((2*n-1)*2^p) = (2*n-2)*(2^p), p>=0.

%F a(2*n-1) = (2*n-2), n>=1, and a(2^p+1) = 2^p, p>=1. (End)

%e a(6) = 6 AND 5 = binary 110 AND 101 = binary 100 = 4.

%p nmax := 75: for p from 0 to ceil(simplify(log[2](nmax))) do for n from 1 to ceil(nmax/(p+2)) do a((2*n-1)*2^p) := (2*n-2) * 2^p od: od: seq(a(n), n=1..nmax); # _Johannes W. Meijer_, Jun 22 2011, revised Jan 25 2013

%p A129760 := n -> Bits:-And(n-1, n):

%p seq(A129760(n), n=1..75); # _Peter Luschny_, Sep 26 2019

%t Table[BitAnd[n, n - 1], {n, 1, 100}] (* _Vladimir Joseph Stephan Orlovsky_, Jul 19 2011 *)

%o (C) int a(int n) { return n & (n-1); }

%o (PARI) a(n)=bitand(n,n-1) \\ _Charles R Greathouse IV_, Jun 23 2011

%o (Magma) [n - 2^Valuation(n, 2): n in [1..100]]; // _Vincenzo Librandi_, Jul 25 2019

%o (Python)

%o def a(n): return n & (n-1)

%o print([a(n) for n in range(1, 71)]) # _Michael S. Branicky_, Jul 13 2022

%Y Cf. A038712, A086799, A104594, A059991, A006519, A109168, A220466.

%K easy,nonn,hear,base

%O 1,3

%A _Russ Cox_, May 15 2007

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 23 16:28 EDT 2024. Contains 371916 sequences. (Running on oeis4.)