login
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

%I #49 Mar 02 2026 03:43:04

%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,-1,1,1,3,3,-1

%N 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.

%H Mark Povich, <a href="/A309983/b309983.txt">Table of n, a(n) for n = 1..10000</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>

%F a(n) = 2*(A029931(n)-A000120(n))-A070939(n)*(A070939(n)-1)/2. - _Chai Wah Wu_, Feb 26 2026

%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.

%p a:= n-> (l-> add(`if`(l[i]=0, 1-i, i-1), i=1..nops(l)))(Bits[Split](n)):

%p seq(a(n), n=1..80); # _Alois P. Heinz_, Feb 26 2026

%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 *)

%t A309983[n_] := Total[#*Range[Length[#], 1, -1]] & [2*Most[IntegerDigits[n, 2]] - 1];

%t Array[A309983, 100] (* _Paolo Xausa_, Mar 01 2026 *)

%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 (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

%o (Python)

%o from math import comb

%o 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

%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 (PARI) a(n)= my(d=[b-!b|b<-binary(n)]); d*-[-#d+1..0]~ \\ _Ruud H.G. van Tol_, Feb 27 2026

%Y Cf. A073642 (when only 1 digits are considered).

%Y Cf. A029931, A000120, A070939.

%Y Cf. A392236 (positions of zeros), A393336.

%K sign,base

%O 1,6

%A _Mark Povich_, Aug 26 2019