This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A145037 #81 May 14 2024 06:10:49 %S A145037 0,1,0,2,-1,1,1,3,-2,0,0,2,0,2,2,4,-3,-1,-1,1,-1,1,1,3,-1,1,1,3,1,3,3, %T A145037 5,-4,-2,-2,0,-2,0,0,2,-2,0,0,2,0,2,2,4,-2,0,0,2,0,2,2,4,0,2,2,4,2,4, %U A145037 4,6,-5,-3,-3,-1,-3,-1,-1,1,-3,-1,-1,1,-1,1,1,3,-3,-1,-1,1,-1,1,1,3,-1,1,1 %N A145037 Number of 1's minus number of 0's in the binary representation of n. %C A145037 Column 2 of A144912 (which begins at n = 2). %C A145037 Zeros in that column correspond to A031443. %H A145037 <a href="/A145037/b145037.txt">Table of n, a(n) for n = 0..2^14</a> %F A145037 a(n) = -A037861(n) for n >= 1. %F A145037 a(n) = Sum_{i=1..k} (2*b[i] - 1) where b is the binary expansion of n and k is the number of bits in this binary expansion. - _Michel Marcus_, Jun 28 2021 %F A145037 From _Aayush Soni_ Feb 12 2022: (Start) %F A145037 Upper bound: a(n) <= floor(log_2(n+1)). %F A145037 Lower bound: For n > 0, a(n) >= 1 - floor(log_2(n)). %F A145037 If n is even, a(2^n) to a(2^(n+1)-1) inclusive are all odd and vice versa. (End) %e A145037 From _Michel Marcus_, Feb 12 2022: (Start) %e A145037 Viewed as an irregular triangle: %e A145037 0; %e A145037 1; %e A145037 0, 2; %e A145037 -1, 1, 1, 3; %e A145037 -2, 0, 0, 2, 0, 2, 2, 4; %e A145037 -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5; %e A145037 ... (End) %p A145037 a:= n-> add(2*i-1, i=Bits[Split](n)): %p A145037 seq(a(n), n=0..90); # _Alois P. Heinz_, Jan 18 2022 %t A145037 Join[{0}, Table[Count[#, 1] - Count[#, 0] &[IntegerDigits[n, 2]], {n, 1, 90}]] (* _Robert P. P. McKone_, Feb 12 2022 *) %o A145037 (Haskell) %o A145037 a145037 0 = 0 %o A145037 a145037 n = a145037 n' + 2*m - 1 where (n', m) = divMod n 2 %o A145037 -- _Reinhard Zumkeller_, Jun 16 2011 %o A145037 (PARI) A145037(n)=hammingweight(n)*2-logint(n<<1+!n,2) \\ _M. F. Hasler_, Mar 08 2018 %o A145037 (Python) %o A145037 result = [0] %o A145037 for n in range (1, 2**14 + 1): %o A145037 result.append(bin(n)[2:].count("1") - bin(n)[2:].count("0")) %o A145037 print(result[0:129]) # _Karl-Heinz Hofmann_, Jan 18 2022 %o A145037 (Python) %o A145037 def a(n): return (n.bit_count()<<1) - n.bit_length() %o A145037 print([a(n) for n in range(1, 2**14+1)]) # _Michael S. Branicky_, May 14 2024 %o A145037 (C#) %o A145037 int A145037(int n) { %o A145037 int result = 0; %o A145037 while(n > 0) { %o A145037 result += 2 * (n % 2) - 1; %o A145037 n /= 2; %o A145037 } %o A145037 return result; %o A145037 } \\ _Frank Hollstein_, Dec 08 2022 %Y A145037 Cf. A037861 (negated), A031443 (indices of 0's), A144912, A000120. %Y A145037 Cf. A269735 (first differences), A268289 (partial sums). %Y A145037 Column k=1 of A360099. %K A145037 sign,base,easy %O A145037 0,4 %A A145037 _Reikku Kulon_, Sep 30 2008 %E A145037 Renamed (using a Mar 08 2018 comment from _M. F. Hasler_) and edited by _Jon E. Schoenfield_, Jun 29 2021