A381852 In the binary expansion of n (without leading zeros): complement the bits strictly to the right of the leftmost zero digit, if any.
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, 25, 24, 29, 28, 30, 31, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 55, 54, 53, 52, 51, 50, 49, 48, 59, 58, 57, 56, 61, 60, 62, 63, 95, 94, 93, 92
Offset: 0
Examples
The first terms, in decimal and in binary, are: n a(n) bin(n) bin(a(n)) -- ---- ------ --------- 0 0 0 0 1 1 1 1 2 2 10 10 3 3 11 11 4 5 100 101 5 4 101 100 6 6 110 110 7 7 111 111 8 11 1000 1011 9 10 1001 1010 10 9 1010 1001 11 8 1011 1000 12 13 1100 1101 13 12 1101 1100 14 14 1110 1110 15 15 1111 1111 16 23 10000 10111
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..8191
- Rémy Sigrist, Colored scatterplot of the sequence for n = 0..2^13-1 (where the color denotes the position of the leftmost zero digit in the binary expansion of n)
- Index entries for sequences related to binary expansion of n
- Index entries for sequences that are permutations of the natural numbers
Programs
-
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); }
-
Python
def a(n): b = bin(n)[2:] zi = b.find('0') return n if zi == -1 else int(b[:zi+1]+"".join('0' if bi == '1' else '1' for bi in b[zi+1:]), 2) print([a(n) for n in range(70)]) # Michael S. Branicky, Mar 09 2025
-
Python
def A381852(n): return n^((1<
Chai Wah Wu, Mar 09 2025
Formula
a(n) = n iff n = 0 or n belongs to A075427.
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
Comments