A309709 Number of binary digits that change when n is multiplied by 4.
0, 2, 2, 4, 2, 2, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 6, 2, 2, 4, 4, 4, 6, 4, 6, 4, 4, 4, 4, 2, 4, 4, 6, 4, 4, 6, 6, 2, 4, 2, 4, 4, 4, 4, 4, 4, 6, 6, 8, 4, 4, 6, 6, 4, 6, 4, 6, 4, 4, 4, 4, 2, 4, 4, 6, 4, 4, 6, 6, 4, 6, 4, 6, 6, 6, 6, 6, 2, 4, 4, 6, 2, 2, 4, 4
Offset: 0
Examples
00101_2 * 100_2 = 10100_2: 2 bits changed, so a(5) = 2.
Links
- David A. Corneth, Table of n, a(n) for n = 0..9999
- Joerg Arndt, Matters Computational (The Fxtbook)
- Index entries for sequences related to binary expansion of n
Programs
-
Maple
a:= n-> add(i, i=Bits[Split](Bits[Xor](n*4,n))): seq(a(n), n=0..120); # Alois P. Heinz, Aug 23 2019
-
Mathematica
a[n_] := Total@ IntegerDigits[BitXor[n, 4 n], 2]; Array[a, 88, 0] (* Giovanni Resta, Sep 19 2019 *)
-
PARI
A309709(n) = hammingweight(bitxor(n, n<<2)); \\ Antti Karttunen, Aug 22 2019
-
Python
def A309709(n): s = "" while n > 0: s, n = str(n%2)+s,n//2 s, s4, i, j = "00"+s, s+"00", 0, 0 while i < len(s): if s[i] != s4[i]: j = j+1 i = i+1 return j # A.H.M. Smeets, Aug 23 2019
Formula
a(A112627(n)) = 2*n and A112627(n) is the first position where 2*n occurs in this sequence. - David A. Corneth, Sep 19 2019
Comments