login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A344220
a(n) is the least k >= 0 such that n XOR k is a binary palindrome (where XOR denotes the bitwise XOR operator).
3
0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2, 3, 2, 1, 0, 1, 0, 3, 2, 1, 0, 3, 2, 3, 2, 1, 0, 3, 2, 1, 0, 1, 0, 3, 2, 5, 4, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 3, 2, 1, 0, 7, 6, 5, 4, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 5, 4, 7, 6, 1, 0, 3
OFFSET
0,11
COMMENTS
The binary expansions of n and of n XOR a(n) have the same length, say k, and their first ceiling(k/2) bits are the same.
FORMULA
a(n) = 0 iff n belongs to A006995.
A070939(n XOR a(n)) = A070939(n).
A344259(n XOR a(n)) = A344259(n).
EXAMPLE
For n=42:
- 42 XOR 0 = 42 ("101010" in binary) is not a binary palindrome,
- 42 XOR 1 = 43 ("101011" in binary) is not a binary palindrome,
- 42 XOR 2 = 40 ("101000" in binary) is not a binary palindrome,
- 42 XOR 3 = 41 ("101001" in binary) is not a binary palindrome,
- 42 XOR 4 = 46 ("101110" in binary) is not a binary palindrome,
- 42 XOR 5 = 47 ("101111" in binary) is not a binary palindrome,
- 42 XOR 6 = 44 ("101100" in binary) is not a binary palindrome,
- 42 XOR 7 = 45 ("101101" in binary) is a binary palindrome,
- so a(42) = 7.
MATHEMATICA
A344220[n_] := Module[{k = -1}, While[!PalindromeQ[IntegerDigits[BitXor[n, ++k], 2]]]; k]; Array[A344220, 100, 0] (* Paolo Xausa, Feb 19 2024 *)
PROG
(PARI) a(n) = my (b); for (k=0, oo, if ((b=binary(bitxor(n, k)))==Vecrev(b), return (k)))
(Python)
from itertools import count
def A344220(n): return next(k for k in count(0) if (s := bin(n^k)[2:])[:(t:=len(s)+1>>1)]==s[:-t-1:-1]) # Chai Wah Wu, Aug 23 2023
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, May 12 2021
STATUS
approved