login
A359495
Sum of positions of 1's in binary expansion minus sum of positions of 1's in reversed binary expansion, where positions in a sequence are read starting with 1 from the left.
14
0, 0, -1, 0, -2, 0, -2, 0, -3, 0, -2, 1, -4, -1, -3, 0, -4, 0, -2, 2, -4, 0, -2, 2, -6, -2, -4, 0, -6, -2, -4, 0, -5, 0, -2, 3, -4, 1, -1, 4, -6, -1, -3, 2, -5, 0, -2, 3, -8, -3, -5, 0, -7, -2, -4, 1, -9, -4, -6, -1, -8, -3, -5, 0, -6, 0, -2, 4, -4, 2, 0, 6
OFFSET
0,5
COMMENTS
Also the sum of partial sums of reversed binary expansion minus sum of partial sums of binary expansion.
LINKS
FORMULA
a(n) = A029931(n) - A230877(n).
If n = Sum_{i=1..k} q_i * 2^(i-1), then a(n) = Sum_{i=1..k} q_i * (2i-k-1).
EXAMPLE
The binary expansion of 158 is (1,0,0,1,1,1,1,0), with positions of 1's {1,4,5,6,7} with sum 23, reversed {2,3,4,5,8} with sum 22, so a(158) = 1.
MAPLE
a:= n-> (l-> add(i*(l[-i]-l[i]), i=1..nops(l)))(Bits[Split](n)):
seq(a(n), n=0..127); # Alois P. Heinz, Jan 09 2023
MATHEMATICA
sap[q_]:=Sum[q[[i]]*(2i-Length[q]-1), {i, Length[q]}];
Table[sap[IntegerDigits[n, 2]], {n, 0, 100}]
PROG
(Python)
def A359495(n):
k = n.bit_length()-1
return sum((i<<1)-k for i, j in enumerate(bin(n)[2:]) if j=='1') # Chai Wah Wu, Jan 09 2023
CROSSREFS
Indices of positive terms are A359401.
Indices of 0's are A359402.
A030190 gives binary expansion, reverse A030308.
A070939 counts binary digits.
A230877 adds up positions of 1's in binary expansion, reverse A029931.
Sequence in context: A183063 A318979 A172441 * A053399 A322996 A242096
KEYWORD
sign,look,base
AUTHOR
Gus Wiseman, Jan 05 2023
STATUS
approved