login
A309983
Numbers resulting from adding the exponents of 2 associated with the "1" terms of their binary representation and subtracting the exponents of 2 associated with the "0" terms of their binary representation.
3
0, 1, 1, 1, 1, 3, 3, 0, 0, 2, 2, 4, 4, 6, 6, -2, -2, 0, 0, 2, 2, 4, 4, 4, 4, 6, 6, 8, 8, 10, 10, -5, -5, -3, -3, -1, -1, 1, 1, 1, 1, 3, 3, 5, 5, 7, 7, 3, 3, 5, 5, 7, 7, 9, 9, 9, 9, 11, 11, 13, 13, 15, 15, -9, -9, -7, -7, -5, -5, -3, -3, -3, -3, -1, -1, 1, 1, 3, 3, -1
OFFSET
1,6
FORMULA
a(n) = 2*(A029931(n)-A000120(n))-A070939(n)*(A070939(n)-1)/2. - Chai Wah Wu, Feb 26 2026
EXAMPLE
When n=18, a(n) = 0. Convert 18 to binary (=10010). The 1s are in the 2^4 place and the 2^1 place. Take those exponents and add them (=5). The 0's are in the 2^3, 2^2, and 2^0 places. Subtract those exponents (=5) from the previous sum to get 0.
When n=26, a(n) = 6. Convert 26 to binary (=11010). The 1s are in the 2^4, 2^3, and 2^1 places. Take those exponents and add them (=8). The 0's are in the 2^2 and 2^0 places. Subtract those exponents (=2) from the previous sum to get 6.
MAPLE
a:= n-> (l-> add(`if`(l[i]=0, 1-i, i-1), i=1..nops(l)))(Bits[Split](n)):
seq(a(n), n=1..80); # Alois P. Heinz, Feb 26 2026
MATHEMATICA
a[n_] := Block[{d = Reverse@IntegerDigits[n, 2]}, Total@ Flatten@ {Position[d, 1]-1, 1-Position[d, 0]}]; Array[a, 74] (* Giovanni Resta, Aug 26 2019 *)
A309983[n_] := Total[#*Range[Length[#], 1, -1]] & [2*Most[IntegerDigits[n, 2]] - 1];
Array[A309983, 100] (* Paolo Xausa, Mar 01 2026 *)
PROG
(Python)
def dec_to_bin(dec_num): #define a function that converts decimal to binary.
bin_num = 0
power = 0
while dec_num > 0:
bin_num += 10 ** power * (dec_num % 2)
dec_num //= 2
power += 1
return bin_num
def rev_bin(n):
return list(reversed(str(dec_to_bin(n))))
n = 18
neg = [pos for pos, num in enumerate(rev_bin(n)) if num == "0"]
posi = [pos for pos, num in enumerate(rev_bin(n)) if num == "1"]
print(sum(posi)-sum(neg))
(Python)
def A309983(n):
r, i = 0, 0
while n > 0:
d, n = n%2, n//2
if d == 1:
r = r+i
else:
r = r-i
i = i+1
return r # A.H.M. Smeets, Oct 07 2019
(Python)
from math import comb
def A309983(n): return (sum(i if j == '1' else 0 for i, j in enumerate(bin(n)[:1:-1]))<<1)-comb(n.bit_length(), 2) # Chai Wah Wu, Feb 26 2026
(PARI) a(n) = {my(b=Vecrev(binary(n))); my(v1 = Vec(select(x->(x==1), b, 1))); my(v0 = Vec(select(x->(x==0), b, 1))); (vecsum(v1) - #v1) - (vecsum(v0) - #v0); } \\ Michel Marcus, Aug 26 2019
(PARI) a(n)= my(d=[b-!b|b<-binary(n)]); d*-[-#d+1..0]~ \\ Ruud H.G. van Tol, Feb 27 2026
CROSSREFS
Cf. A073642 (when only 1 digits are considered).
Cf. A392236 (positions of zeros), A393336.
Sequence in context: A298930 A298895 A179311 * A342697 A360480 A257094
KEYWORD
sign,base
AUTHOR
Mark Povich, Aug 26 2019
STATUS
approved