OFFSET
1,1
COMMENTS
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
Rémy Sigrist, Table of n, a(n) and binary palindromes for n = 1..10000
EXAMPLE
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.
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.
MATHEMATICA
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 *)
PROG
(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
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Jul 12 2009
EXTENSIONS
More terms from Rémy Sigrist, Nov 08 2018
STATUS
approved