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.

A381852 In the binary expansion of n (without leading zeros): complement the bits strictly to the right of the leftmost zero digit, if any.

This page as a plain text file.
%I A381852 #14 Mar 10 2025 11:11:53
%S A381852 0,1,2,3,5,4,6,7,11,10,9,8,13,12,14,15,23,22,21,20,19,18,17,16,27,26,
%T A381852 25,24,29,28,30,31,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,55,
%U A381852 54,53,52,51,50,49,48,59,58,57,56,61,60,62,63,95,94,93,92
%N A381852 In the binary expansion of n (without leading zeros): complement the bits strictly to the right of the leftmost zero digit, if any.
%C A381852 This sequence is a self-inverse permutation of the nonnegative integers.
%C A381852 This sequence has similarities with A054429 (where we complement the bits to the right of the leftmost one digit).
%H A381852 Rémy Sigrist, <a href="/A381852/b381852.txt">Table of n, a(n) for n = 0..8191</a>
%H A381852 Rémy Sigrist, <a href="/A381852/a381852.png">Colored scatterplot of the sequence for n = 0..2^13-1</a> (where the color denotes the position of the leftmost zero digit in the binary expansion of n)
%H A381852 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%H A381852 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A381852 a(n) = n iff n = 0 or n belongs to A075427.
%F A381852 a(n) = XOR(n,2^(A063250(n)-1)-1) if n>0 and A063250(n)>0. Otherwise a(n) = n. - _Chai Wah Wu_, Mar 09 2025
%e A381852 The first terms, in decimal and in binary, are:
%e A381852   n   a(n)  bin(n)  bin(a(n))
%e A381852   --  ----  ------  ---------
%e A381852    0     0       0          0
%e A381852    1     1       1          1
%e A381852    2     2      10         10
%e A381852    3     3      11         11
%e A381852    4     5     100        101
%e A381852    5     4     101        100
%e A381852    6     6     110        110
%e A381852    7     7     111        111
%e A381852    8    11    1000       1011
%e A381852    9    10    1001       1010
%e A381852   10     9    1010       1001
%e A381852   11     8    1011       1000
%e A381852   12    13    1100       1101
%e A381852   13    12    1101       1100
%e A381852   14    14    1110       1110
%e A381852   15    15    1111       1111
%e A381852   16    23   10000      10111
%o A381852 (PARI) a(n) = { my (b = binary(n)); for (i = 1, #b, if (b[i]==0, for (j = i+1, #b, b[j] = 1-b[j];); return (fromdigits(b, 2)););); return (n); }
%o A381852 (Python)
%o A381852 def a(n):
%o A381852     b = bin(n)[2:]
%o A381852     zi = b.find('0')
%o A381852     return n if zi == -1 else int(b[:zi+1]+"".join('0' if bi == '1' else '1' for bi in b[zi+1:]), 2)
%o A381852 print([a(n) for n in range(70)]) # _Michael S. Branicky_, Mar 09 2025
%o A381852 (Python)
%o A381852 def A381852(n): return n^((1<<n.bit_length()-t-1)-1) if n and (t:=bin(n)[2:].find('0'))!=-1 else n # _Chai Wah Wu_, Mar 09 2025
%Y A381852 Cf. A054429, A063250, A075427, A381839.
%K A381852 nonn,base,easy
%O A381852 0,3
%A A381852 _Rémy Sigrist_, Mar 08 2025