%I #21 Feb 06 2023 16:22:47
%S 3,1,9,15,5,7,33,45,51,63,17,21,27,31,129,153,165,189,195,219,231,255,
%T 65,73,85,93,99,107,119,127,513,561,585,633,645,693,717,765,771,819,
%U 843,891,903,951,975,1023,257,273,297,313,325,341,365,381,387,403,427
%N Write the n-th (odd) binary palindrome in binary. If there are an even number of digits, then combine the middle two digits into one digit. If there are an odd number of digits, then double the middle digit. a(n) is the decimal result.
%C a(n) is the A162750(n)th (odd) binary palindrome written in decimal. This sequence (A162749) is a permutation of the (odd) positive integers that are each palindromes when written in base 2.
%H Rémy Sigrist, <a href="/A162749/b162749.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A162749/a162749.txt">Table of n, a(n) and binary palindromes for n = 1..10000</a>
%e The 8th binary palindrome is 21, which is 10101 in binary. Since there are an odd number of digits, double the middle digit to get 101101. a(8) is this written in decimal, which is 45.
%e 51, the 13th palindrome when written in binary, is 110011 when written in base 2. Since this has an even number of digits, combine the middle two digits into one digit to get 11011. a(13) is the decimal equivalent of this, which is 27.
%t bp[n_]:=Module[{len=Length[n]},If[OddQ[len],FromDigits[Insert[n,n[[(len+1)/2]],(len+ 1)/2],2],FromDigits[Delete[n,len/2],2]]]; bp/@Select[Table[IntegerDigits[n,2],{n,1000}],PalindromeQ] (* _Harvey P. Dale_, Feb 06 2023 *)
%o (PARI) a(n) = my (p=A006995(n+1)); my (l=#binary(p), l2=2^ceil(l/2)); if (l%2==0, (p\(l2*2))*l2+(p%l2), (p\(l2\2))*l2+(p%l2)) \\ _Rémy Sigrist_, Nov 08 2018
%Y Cf. A006995, A162750.
%K base,nonn
%O 1,1
%A _Leroy Quet_, Jul 12 2009
%E More terms from _Rémy Sigrist_, Nov 08 2018