%I #30 Apr 07 2020 23:24:37
%S 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,
%T -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,
%U 15,15,-9,-9,-7,-7,-5,-5,-3,-3,-3,-3,-1
%N Numbers n 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.
%H Mark Povich, <a href="/A309983/b309983.txt">Table of n, a(n) for n = 1..9999</a>
%H noyonict, <a href="https://github.com/noyonict/Number-conversion-in-Python-3/blob/master/decimal_to_binary.py">Number conversion in Python 3</a>
%e 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.
%e 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.
%t 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 *)
%o (Python)
%o def dec_to_bin(dec_num): #define a function that converts decimal to binary.
%o bin_num = 0
%o power = 0
%o while dec_num > 0:
%o bin_num += 10 ** power * (dec_num % 2)
%o dec_num //= 2
%o power += 1
%o return bin_num
%o def rev_bin(n):
%o return list(reversed(str(dec_to_bin(n))))
%o n = 18
%o neg = [pos for pos, num in enumerate(rev_bin(n)) if num == "0"]
%o posi = [pos for pos, num in enumerate(rev_bin(n)) if num == "1"]
%o print(sum(posi)-sum(neg))
%o (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
%o (Python)
%o def A309983(n):
%o r, i = 0, 0
%o while n > 0:
%o d, n = n%2, n//2
%o if d == 1:
%o r = r+i
%o else:
%o r = r-i
%o i = i+1
%o return r # _A.H.M. Smeets_, Oct 07 2019
%Y Cf. A073642 (when only 1 digits are considered).
%K sign,base
%O 1,6
%A _Mark Povich_, Aug 26 2019