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.

A382865 Bitwise XOR of all integers between n and 2n (endpoints included).

Original entry on oeis.org

0, 3, 5, 4, 8, 15, 13, 8, 16, 27, 21, 28, 24, 23, 29, 16, 32, 51, 37, 52, 40, 63, 45, 56, 48, 43, 53, 44, 56, 39, 61, 32, 64, 99, 69, 100, 72, 111, 77, 104, 80, 123, 85, 124, 88, 119, 93, 112, 96, 83, 101, 84, 104, 95, 109, 88, 112, 75, 117, 76, 120, 71, 125, 64, 128, 195
Offset: 0

Views

Author

Federico Provvedi, May 21 2025

Keywords

Examples

			a(3) = 3 XOR 4 XOR 5 XOR 6 = 4, in binary representation is: ((011 XOR 100) XOR 101) XOR 110 = (111 XOR 101) XOR 110 = 010 XOR 110 = 100 (4 in decimal).
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember; uses Bits; `if`(n=0, 0,
          Xor(Xor(Xor(a(n-1), n-1), 2*n-1), 2*n))
        end:
    seq(a(n), n=0..65);  # Alois P. Heinz, May 26 2025
  • Mathematica
    a[n_] = BitXor[BitOr[n-1, 2] - (-1)^n*(n-1), 4*n]/2; Table[a[n],{n,0, 65}]
  • PARI
    a(n) = my(b=n); for (i=n+1, 2*n, b = bitxor(b, i)); b; \\ Michel Marcus, May 25 2025
    
  • Python
    def A382865(n): return [0, n, 1, n-1][n%4] ^ (2*n) # Karl-Heinz Hofmann, May 26 2025

Formula

a(2n) = A047615(n+1), and for every integer k>1: a(n*2^k -1) = 2^k * A065621(n).
a(4n) = 8*n, a(4n+1) = 2*A114389(n+1) + 1, a(4n+2) = 8*n + 5, a(4n+3) = 4*A065621(n+1).
From Karl-Heinz Hofmann, May 27 2025: (Start)
For all n == 0 (mod 4) --> a(n) = A005843(n) = 2*n
For all n == 1 (mod 4) --> a(n) = A048724(n)
For all n == 2 (mod 4) --> a(n) = A005408(n) = 2*n + 1
For all n == 3 (mod 4) --> a(n) = A048724(n) - 1 (End)
a(n) = (1/2) * XOR(A174091(n-1) - A181983(n-1), 4*n). - Federico Provvedi, May 31 2025