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”).

A309952
XOR contraction of binary representation of n.
1
0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 1, 1, 0, 4, 5, 5, 4, 6, 7, 7, 6, 6, 7, 7, 6, 4, 5, 5, 4, 4, 5, 5, 4, 6, 7, 7, 6, 6, 7, 7, 6, 4, 5, 5, 4, 0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 1, 1, 0, 8, 9, 9, 8, 10, 11, 11, 10, 10, 11, 11, 10, 8, 9, 9, 8, 12, 13, 13
OFFSET
0,5
COMMENTS
To calculate a(n) write down the binary representation of n. Organize the digits in pairs and calculate the xor of these pairs. The result is a(n) in binary.
Conjecture: The index of the first occurrence of k in a is A000695(k). - Ivan N. Ianakiev, Aug 26 2019
FORMULA
a(n) = A292371(n) + A292372(n). - Rémy Sigrist, Aug 25 2019
a(0) = 0, a(4n) = 2*a(n), a(4n+1) = 2*a(n)+1, a(4n+2) = 2*a(n)+1, a(4n+3) = 2*a(n). - Florian Lang, Aug 26 2019
EXAMPLE
For n=19 we have the binary representation 10011 = 01 00 11. Calculating the xor of the pairs gives 1 0 0 which is 4 in binary and therefore a(19) = 4.
MAPLE
a:= n-> `if`(n=0, 0, (r-> 2*a((n-r)/4) +r*(3-r)/2)(irem(n, 4))):
seq(a(n), n=0..100); # Alois P. Heinz, Aug 26 2019
PROG
(Python)
def a(n):
n = [int(k) for k in bin(n)[2:]]
if len(n) % 2 != 0:
n = [0] + n
result = []
for i in range(0, len(n), 2):
result.append(n[i] ^ n[i+1]) #xor
return int("".join([str(k) for k in result]), 2)
(Python)
from itertools import zip_longest
from operator import xor
def A309952(n): return int(''.join(map(lambda x:str(xor(*x)), zip_longest((s:=tuple(int(d) for d in bin(n)[2:]))[::-2], s[-2::-2], fillvalue=0)))[::-1], 2) # Chai Wah Wu, Jun 30 2022
(PARI) a(n) = {my(b = Vecrev(binary(n)), nb = #b\2, val = fromdigits(Vecrev(vector(nb, i, bitxor(b[2*i-1], b[2*i]))), 2)); if (#b % 2, val += 2^nb); val; } \\ Michel Marcus, Aug 26 2019
CROSSREFS
KEYWORD
base,easy,look,nonn
AUTHOR
Florian Lang, Aug 24 2019
STATUS
approved