cp's OEIS Frontend

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.

A342126 The binary expansion of a(n) corresponds to that of n where all the 1's have been replaced by 0's except in the first run of 1's.

This page as a plain text file.
%I A342126 #20 Apr 30 2021 17:17:10
%S A342126 0,1,2,3,4,4,6,7,8,8,8,8,12,12,14,15,16,16,16,16,16,16,16,16,24,24,24,
%T A342126 24,28,28,30,31,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,48,48,
%U A342126 48,48,48,48,48,48,56,56,56,56,60,60,62,63,64,64,64,64
%N A342126 The binary expansion of a(n) corresponds to that of n where all the 1's have been replaced by 0's except in the first run of 1's.
%C A342126 In other words, this sequence gives the first run of 1's in the binary expansion of a number.
%C A342126 A023758(n) appears A057728(n) times.
%H A342126 Rémy Sigrist, <a href="/A342126/b342126.txt">Table of n, a(n) for n = 0..8192</a>
%H A342126 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A342126 a(n) = n - A087734(n).
%F A342126 a(2*n) = 2*a(n).
%F A342126 a(a(n)) = a(n).
%F A342126 a(n) <= n with equality iff n belongs to A023758.
%e A342126 The first terms, alongside their binary expansion, are:
%e A342126   n   a(n)  bin(n)  bin(a(n))
%e A342126   --  ----  ------  ---------
%e A342126    0     0       0          0
%e A342126    1     1       1          1
%e A342126    2     2      10         10
%e A342126    3     3      11         11
%e A342126    4     4     100        100
%e A342126    5     4     101        100
%e A342126    6     6     110        110
%e A342126    7     7     111        111
%e A342126    8     8    1000       1000
%e A342126    9     8    1001       1000
%e A342126   10     8    1010       1000
%e A342126   11     8    1011       1000
%e A342126   12    12    1100       1100
%e A342126   13    12    1101       1100
%e A342126   14    14    1110       1110
%e A342126   15    15    1111       1111
%o A342126 (PARI) a(n) = { my (b=binary(n), p=1); for (k=1, #b, b[k] = p*=b[k]); fromdigits(b, 2) }
%o A342126 (Python)
%o A342126 def A342126(n):
%o A342126     s = bin(n)[2:]
%o A342126     i = s.find('0')
%o A342126     return n if i == -1 else (2**i-1)*2**(len(s)-i) # _Chai Wah Wu_, Apr 29 2021
%Y A342126 Cf. A023758, A057728, A087734, A090996, A342410.
%K A342126 nonn,base,easy
%O A342126 0,3
%A A342126 _Rémy Sigrist_, Apr 25 2021