login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A309952 XOR contraction of binary representation of n. 1

%I #47 Jun 30 2022 14:44:07

%S 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,

%T 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,

%U 10,11,11,10,10,11,11,10,8,9,9,8,12,13,13

%N XOR contraction of binary representation of n.

%C 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.

%C Conjecture: The index of the first occurrence of k in a is A000695(k). - _Ivan N. Ianakiev_, Aug 26 2019

%H Alois P. Heinz, <a href="/A309952/b309952.txt">Table of n, a(n) for n = 0..16383</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F a(n) = A292371(n) + A292372(n). - _Rémy Sigrist_, Aug 25 2019

%F 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

%e 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.

%p a:= n-> `if`(n=0, 0, (r-> 2*a((n-r)/4) +r*(3-r)/2)(irem(n, 4))):

%p seq(a(n), n=0..100); # _Alois P. Heinz_, Aug 26 2019

%o (Python)

%o def a(n):

%o n = [int(k) for k in bin(n)[2:]]

%o if len(n) % 2 != 0:

%o n = [0] + n

%o result = []

%o for i in range(0, len(n), 2):

%o result.append(n[i] ^ n[i+1]) #xor

%o return int("".join([str(k) for k in result]), 2)

%o (Python)

%o from itertools import zip_longest

%o from operator import xor

%o 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

%o (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

%Y Cf. A000695, A292371, A292372, A292373.

%K base,easy,look,nonn

%O 0,5

%A _Florian Lang_, Aug 24 2019

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 00:30 EDT 2024. Contains 371917 sequences. (Running on oeis4.)