cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-1 of 1 results.

A344220 a(n) is the least k >= 0 such that n XOR k is a binary palindrome (where XOR denotes the bitwise XOR operator).

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, May 12 2021

Keywords

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.

Examples

			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.
		

Crossrefs

Programs

  • Mathematica
    A344220[n_] := Module[{k = -1}, While[!PalindromeQ[IntegerDigits[BitXor[n, ++k], 2]]];k]; Array[A344220, 100, 0] (* Paolo Xausa, Feb 19 2024 *)
  • 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

Formula

a(n) = 0 iff n belongs to A006995.
A070939(n XOR a(n)) = A070939(n).
A344259(n XOR a(n)) = A344259(n).
Showing 1-1 of 1 results.