OFFSET
0,4
COMMENTS
A weighted variant of A037861.
Position 1 corresponds to the least significant bit of n.
Conjecture: the sequence contains all integers.
Above conjecture is true. All positive integers are attained when n in binary is of the form 101010...10. All nonpositive integers are attained when n in binary is of the form 1001010101..01. - Chai Wah Wu, Feb 27 2026
LINKS
Ruud H.G. van Tol, Table of n, a(n) for n = 0..10000
FORMULA
EXAMPLE
a(6) = 4, because 6 = 110_2, and -1+2+3 = 4.
a(8) = -2, because 8 = 1000_2, and -1-2-3+4 = -2.
MAPLE
a:= n-> (l-> add(`if`(l[i]=0, -i, i), i=1..nops(l)))(convert(n, base, 2)):
seq(a(n), n=0..74); # Alois P. Heinz, Feb 26 2026
MATHEMATICA
A393336[n_] := Total[#*Range[Length[#], 1, -1]] & [2*IntegerDigits[n, 2] - 1];
Array[A393336, 100, 0] (* Paolo Xausa, Feb 26 2026 *)
PROG
(PARI) a(n)= my(d=Vecrev([ b-!b |b<-if(n, binary(n), [0])])); d*[1..#d]~
(PARI) a(n)= my(d=binary(n)); 2*d*-[-#d..-1]~ - binomial(#d+1, 2) - !n \\ Ruud H.G. van Tol, Feb 27 2026
(Python)
from math import comb
def A393336(n): return (sum(i if j == '1' else 0 for i, j in enumerate(bin(n)[:1:-1], 1))<<1)-comb(n.bit_length()+1, 2) if n else -1 # Chai Wah Wu, Feb 26 2026
CROSSREFS
KEYWORD
sign,easy,base
AUTHOR
Ruud H.G. van Tol, Feb 12 2026
STATUS
approved
