login
a(n) = n XOR A086893(1+A000523(n)), where XOR is a bitwise-XOR, A003987.
6

%I #17 May 03 2024 15:41:08

%S 0,1,0,1,0,3,2,5,4,7,6,1,0,3,2,5,4,7,6,1,0,3,2,13,12,15,14,9,8,11,10,

%T 21,20,23,22,17,16,19,18,29,28,31,30,25,24,27,26,5,4,7,6,1,0,3,2,13,

%U 12,15,14,9,8,11,10,21,20,23,22,17,16,19,18,29,28,31,30,25,24,27,26,5,4,7,6,1,0,3,2,13,12,15

%N a(n) = n XOR A086893(1+A000523(n)), where XOR is a bitwise-XOR, A003987.

%C a(n) gives n xored with the unique term of A086893 that has the same binary length as n itself. The binary expansions of the terms of A086893 are of the form 10101...0101 (i.e., alternating 1's and 0's starting and ending with 1) when the binary length is odd, and of the form 110101...0101 (i.e., 1 followed by alternating 1's and 0's, and ending with 1) when the binary length is even. In other words, a(n) is n with its all its even-positioned bits (indexing starts from 0 which stands for the least significant bit) inverted, and additionally also the odd-positioned most significant bit inverted if the number of significant bits is even (i.e., n is a nonzero term of A053754).

%H Antti Karttunen, <a href="/A372358/b372358.txt">Table of n, a(n) for n = 1..16384</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%e 25 in binary is 11001_2, and inverting all the even-positioned bits gives 01100_2, and as A007088(12) = 1100, a(25) = 12.

%e 46 in binary is 101110_2, so we flip all the even-positioned bits (starting from the rightmost, with position 0), and because there are even number of bits in the binary expansion, we flip also the most significant bit, thus we obtain 011011_2, and as A007088(27) = 11011, a(46) = 27.

%o (PARI)

%o A000523(n) = logint(n,2);

%o A086893(n) = (if(n%2, 2^(n+1), 2^(n+1)+2^(n-1))\3); \\ From A086893

%o A372358(n) = bitxor(n, A086893(1+A000523(n)));

%Y Cf. A000523, A003987, A007088, A053754, A086893 (positions of 0's), A372359, A372360, A372361, A372446.

%K nonn,base,easy

%O 1,6

%A _Antti Karttunen_, May 01 2024