login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A309983 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. 1
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 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,6
LINKS
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.
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 *)
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))
(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
(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
CROSSREFS
Cf. A073642 (when only 1 digits are considered).
Sequence in context: A298930 A298895 A179311 * A342697 A360480 A257094
KEYWORD
sign,base
AUTHOR
Mark Povich, Aug 26 2019
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified May 9 08:36 EDT 2024. Contains 372346 sequences. (Running on oeis4.)